[英]Join one table rows with another table columns in mysql
我是 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
如果可能,請幫助。
您可能想查看有關數據庫設計的相同教程。 網上有很多不錯的。 同時,這可能對您有所幫助:似乎您可能需要一個“人”或類似的表格,例如:
TABLE persons
person_id int autoincrement primary key
person_name varchar(45)
--------
persons_attributes
然后你會有一個問題表記錄一個人的屬性是什么時候被取的
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
你可能需要額外的表格:communication_skills; 推理技能; 和 Technical_skill 格式為:
TABLE xxx_skills
xxx_skill_id int
grade varchar(30) #"below average", "average", "good","best"
然后你可以加入你的表:
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.