我有一个查询:
SELECT g.name, s.hour, gs.weekday
FROM schedule s
INNER JOIN group_schedule gs ON gs.schedule_id = s.id
INNER JOIN groups g ON g.id = gs.group_id
WHERE EXISTS (
SELECT *
FROM group_schedule
WHERE group_id =6
)
ORDER BY g.name, gs.weekday
返回:
name hour weekday
A1-A2 10:00:00 1
A1-A2 17:00:00 1
A1-A2 10:30:00 1
A1-A2 17:30:00 1
A1-A2 18:00:00 2
A1-A2 11:30:00 2
A1-A2 18:30:00 2
A1-A2 11:00:00 2
A1-A2 12:30:00 3
但我也需要获取没有这些组合的行,例如:
name hour weekday
A1-A2 10:30:00 1
A1-A2 11:00:00 1
A1-A2 11:30:00 1
...
如果我使用 NOT EXISTS,我会得到一个空表。