简体   繁体   English

将一个表行与mysql中的另一个表列连接起来

[英]Join one table rows with another table columns in mysql

I am new to mysql, Need to join two tables as below scenario我是 mysql 的新手,需要加入两个表,如下所示

Table One : questions{question_id,question}
Example: question_id  question
         q01          communication skills
         q02          reasoning skills
         q03          technical skills

Table Two : grades{grade_id,grade}
Example : grade_id  grade
          gr01      below avg
          gr02      avg
          gr03      good
          gr04      best

Want to join above two tables for below result
         question_id  question               gr01        gr02  gr03    gr04            
         q01          communication skills   below avg   avg   good    best 
         q02          reasoning skills       below avg   avg   good    best 
         q03          technical skills       below avg   avg   good    best 

Please help if it is possible.如果可能,请帮助。

You may want to have a look to same tutorial on database design.您可能想查看有关数据库设计的相同教程。 There are many good ones on the web.网上有很多不错的。 In the mean time, this may help you a little bit: It seems you may need a table for 'persons' or similar such as:同时,这可能对您有所帮助:似乎您可能需要一个“人”或类似的表格,例如:

TABLE persons
person_id int autoincrement primary key
person_name varchar(45)
--------
persons_attributes

Then you will have a questions table recording when the attributes of a person were taken然后你会有一个问题表记录一个人的属性是什么时候被取的

Table questions
question_id int autoincrement primary key
personid int
date_input date
communication_skills_id int
reasoning_skills_id int
technical_skills_id int

and you may need extra tables for: communication_skills;你可能需要额外的表格:communication_skills; reasoning_skills;推理技能; and technical_skill with a format as:和 Technical_skill 格式为:

TABLE xxx_skills
xxx_skill_id int 
grade varchar(30) #"below average", "average", "good","best"

Then you may join your tables as:然后你可以加入你的表:

SELECT p.person_name, q.date_input, c.grade communication_skill, r.grade reasoning_skill, t.grade technical_skill
  FROM questions q
    INNER JOIN persons p
    on q.person_id = p.person_id
    INNER JOIN communication_skills c
    ON q.communication_id = c.communication_id
    INNER JOIN reasoning_skills r
    ON q.reasoning_skills_id = reasoning_skills_id
    INNER JOIN technical_skill t
    ON q.technical_skills_id = t.technical_skills_id;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM