0

我有两种日期格式,一种是 2013-01-01 到 2013-01-10,我有时间两次,一种是 20:00:00 到 23:59:59 和 00:00:00 到 07:00:00 和我正在使用 for 循环迭代开始日期到结束日期,我期望以下

询问:

select * from user where login >='$starttime' and logout <='$endtime' and  date='$StartDate';

预期结果:

select * from user where login >='20:00:00' and logout <='23:59:59' and  date='2013-01-01';
select * from user where login >='00:00:00' and logout <='07:00:00' and  date='2013-01-02';

如何使用 if 条件获得预期结果

4

1 回答 1

0
select * from user where (login >='20:00:00' and logout <='23:59:59' and  date='2013-01-01') OR (login >='00:00:00' and logout <='07:00:00' and  date='2013-01-02');

如果时间相同,但您需要一个日期范围:

SELECT * FROM `user`
WHERE `login` >='20:00:00' AND `logout` <='23:59:59' AND  `date` between '2013-01-01' AND '2013-01-02';
于 2013-10-11T06:35:37.340 回答