題目:查詢所有學生的課程及分數情況(存在學生沒成績,沒選課的情況)
分析: 這個應該是student表 和 student_score表進行聯合查詢,因為存在學生沒成績,沒選課的情況,所以要用left join
SELECT student.*,student_score.courseid ,student_score.score FROM student
LEFT JOIN student_score ON student.id = student_score.studentid
27:查詢任何一門課程成績在 70 分以上的姓名、課程名稱和分數
分析: 這個是個很簡單的普通查詢,但是要得到 姓名,課程名稱,分數 就要關聯 student student_course student_score等三張表
SELECT student.stdentname,student_course.coursename, student_score.score
FROM student_score, student_course, student WHERE student_score.score >70
AND student_score.studentid = student.id AND student_score.courseid = student_course.id