Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的桌子是:
我想选择所有失败的记录(结果 = 0),但除了具有相同 course_id 结果为 1 的记录。
例如,看看我的表有两行结果=0,但 student_id=1 有另一行结果=1,所以我想跳过这条记录。
很抱歉让您感到困惑。我希望我的预期输出清楚地解释了我想要什么。
预期输出是:
2 | 1 | 0
尝试这个
SELECT student_id, course_id, result FROM tbl WHERE result = 0 AND student_id NOT IN (SELECT student_id FROM table WHERE result =1 and course_id = tbl.course_id )
上面我们选择result =0只有当在子查询中找不到 student_id 和 course_id 时才具有 a 的所有记录result=1
result =0
result=1