2011-08-28 40 views
-1

我想通过左侧将我的时间表与我的时间表连接起来,来获取特定日期的所有可用时间段列表。选择特定日期的可用时间段

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

试试这个:

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 
+0

像魅力一样工作,感谢您的帮助。 – PhoenixDown

1

只需添加一个WHERE

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

但我相信,消除了2011-08-02时隙,以及,我不希望出现这种情况。只有2011-08-01或某个任意日期的。 - 谢谢 – PhoenixDown

+0

@PhoenixDown:你说“我要返回的是最后3个字段为空的所有行”。我已经做到了。请修复您的问题 – gbn

相关问题