0

我有这个 sql 查询,我必须提供 ID 才能工作(在这个例子中是 100)

SELECT * FROM students_subjects WHERE student_id 
NOT IN 
(SELECT student_id FROM students_info WHERE class_id=(SELECT class_id FROM groups WHERE group_id=(SELECT group_id FROM teacher_groups_subjects WHERE t_g_s_id=**100**)))

我想从表 teacher_groups_subjects 中选择所有行并为每个 ID (t_g_s_id) 运行上面的查询

任何人?

4

1 回答 1

0

可能是这样的:-

SELECT * 
FROM students_subjects a 
LEFT OUTER JOIN students_info b ON a.student_id = b.student_id
LEFT OUTER JOIN groups c ON b.class_id = c.group_id
LEFT OUTER JOIN teacher_groups_subjects d ON c.group_id = d.group_id
WHERE b.student_id IS NULL
于 2012-11-05T09:08:04.450 回答