如何选择未在某些子课程中标记的学生的分数
edu_submark:
Id sm_mark sub_lesson_id st_id course_id
1 97 1 9 3
2 66 2 9 3
3 22 2 1012 3
4 32 1 1012 3
1002 15 1 13 3
edu_sub_lesson:
Id sl_title lesson_id
1 Active Directory 2
2 Win7 2
2009 UI 1
2011 Win SERVER 2008 R2 2
我使用了这个查询:
SELECT
a.sl_title, b.sm_mark
FROM
edu_sublesson a
LEFT JOIN
edu_submark b on a.Id = b.sub_lesson_id
WHERE
lesson_id = 2 AND course_id = 3 AND st_id = 9
结果:
Active Directory 99.9
Win 7 75
但我想要这个结果:
Active Directory 99.9
Win Server NULL
Win 7 75
答案 0 :(得分:0)
如果从
更改WHERE子句WHERE
lesson_id = 2 AND course_id = 3 AND st_id = 9
到这个
WHERE
-- Restrict to specific lesson/course etc..
(lesson_id = 2 AND course_id = 3 AND st_id = 9)
-- return any which don't have marks
OR sm_mark IS NULL
答案 1 :(得分:0)
尝试将您的查询更改为
SELECT
a.sl_title, b.sm_mark
FROM
edu_sublesson a
LEFT JOIN
edu_submark b on a.Id = b.sub_lesson_id AND b.course_id = 3 AND b.st_id = 9
WHERE
a.lesson_id = 2
答案 2 :(得分:-1)
好吧也许你应该这样做:
SELECT
a.sl_title, b.sm_mark, WinServer, Administration
或者这个字段有什么名字..