选择特定日期的可用时间段

时间:2011-08-28 17:23:13

标签: mysql

我试图通过将我的时间表与我的日程表连接起来,获取特定日期的所有可用时间列表。

SELECT * 
FROM `timeslots` 
LEFT JOIN schedule ON timeslots.timeslot_id = schedule.schedule_timeslot 
LIMIT 0, 30

返回:

enter image description here

我想要返回的是最后3个字段为空的所有行。所以考虑到2011-08-01的日期,除了08:30 - 10:30之外,我希望所有的时间段都返回。我假设需要某种子查询,但我不知道该怎么做。

任何帮助都将不胜感激。

2 个答案:

答案 0 :(得分:2)

试试这个:

SELECT * 
FROM `timeslots` 
LEFT JOIN schedule ON timeslots.timeslot_id = schedule.schedule_timeslot
WHERE  schedule.schedule_id IS NULL or schedule.schedule_date <> '2011-08-01'
LIMIT 0, 30

答案 1 :(得分:1)

只需添加一个WHERE

SELECT * 
FROM `timeslots` 
LEFT JOIN schedule ON timeslots.timeslot_id = schedule.schedule_timeslot 
WHERE schedule.schedule_timeslot IS NULL
LIMIT 0, 30
相关问题