我有一个这样的表,我需要结果只是UserId 11,因为UserId 12不是lessonId 103但仍然得到结果。
SELECT *
FROM LessonList
WHERE
(LessonId = 102 and LessonValue = 1002)
or
(LessonId = 103 and LessonValue = 1003)
or
(LessonId = 102 and LessonValue = 1008)
输出:
Id UserId LessonId LessonValue
1 11 102 1002
2 11 103 1003
3 12 102 1008
我需要这样的结果:
Id UserId LessonId LessonValue
1 11 102 1002
2 11 103 1003
由于
答案 0 :(得分:2)
您可以使用聚合:
WHERE
这将返回有两个课程ID的用户。由于IN
子句,这意味着它们同时具有102和103. {{1}}只是简化了查询逻辑。
答案 1 :(得分:0)
SELECT *
FROM LessonList
WHERE
(LessonId = 102 and LessonValue = 1002)
or
(LessonId = 103 and LessonValue = 1003)
and lessonvalue<>1008