我有特定日期的两次检查室.
我尝试跟随两个查询它运行一些时间权限但是,当我选择上午10:00到下午12:00时错误结果意味着不返回任何记录.
QUERY-1:
SELECT 1 FROM `tiMetable_details` WHERE (
((`td_from` <= '10:00:00') AND (`td_to` > '10:00:00'))
OR
((`td_from` < '12:20:00') AND (`td_to` >= '12:20:00'))
) AND ((`td_room`='1') AND (`td_date`='2016-01-25'))
QUERY-2:
SELECT 1 FROM `tiMetable_details` WHERE (
(`td_from` > '07:00:00') AND (`td_to` < '08:00:00')
) AND ((`td_room`='1') AND (`td_date`='2016-01-25'))
我得到td_id = 4号码但不返回.
提前致谢.
最佳答案
您可以在两个列之间使用OR条件,如下所示:
SELECT 1 FROM `tiMetable_details` WHERE (((((`td_from` BETWEEN '10:00:00' AND '12:30:00') OR (`td_to` BETWEEN '10:00:00' AND '12:30:00')) AND ((`td_room`='1') AND (`td_date`='2016-01-25') AND (`td_status` IS NULL))) AND (`td_from` <> '12:30:00')) AND (`td_to` <> '10:00:00'))
希望你能得到正确的结果.