我有5个表,如下所示:
学生(Student_ID,First_Name,Last_Name,Section_ID)
章节(Section_ID,Section_Title)
主题(Subject_ID,Subject_Title)
考试(Exam_ID,Exam_Title)
Stu_Marks(Student_ID,Section_ID,Subject_ID,Exam_ID Mark)
我想检索未参加4门考试的学生的姓名。 (少于4次考试或没有记录)
我有这个问题:
SELECT First_Name,Subject_Title,Section_Title
FROM students s left join `Stu_Marks` sm
on sm.Student_ID=s.Student_ID
left join subjects j
on sm.Subject_ID=j.Subject_ID
left join Sections l
on sm.Section_ID=l.Section_ID
group by sm.`Student_ID`,sm.Subject_ID
having count(sm.Student_ID)<4
这将返回所有未参加全部4门考试的学生。但不要退还所有考试都没有分数的学生(Stu_Marks表中按学科分组的学生没有记录)
任何帮助?
*对不起我的英语不好:(
谢谢,