我在表格中有以下内容
--2,4,1| 2016-02-21 10:22:00 | 2016-02-21 12:22:00 --
即id's(varchar)
,fromtime(datetime)
和totime(datetime)
我希望在使用
时返回此ID设置Select ids
from Schedule
where fromtime between '2016/02/21 10:00:00' and '2016/02/21 12:00:00'
and totime between '2016/02/21 10:00:00' and '2016/02/21 12:00:00'
但是如果使用此查询
,它会返回空集Select Participantsids
from Schedule
where fromtime between '2016/02/21 10:00:00' and '2016/02/21 13:00:00'
and totime between '2016/02/21 10:00:00' and '2016/02/21 13:00:00';
它会返回所需的结果。我需要完全覆盖fromtime
和totime
以获得我的结果。当我的时间如10:30 - 12时,有办法获得结果:00?
答案 0 :(得分:1)
要检查重叠间隔,请使用以下谓词:
SELECT ids
FROM Schedule
WHERE fromtime <= '2016-02-21 12:00:00' AND totime >= '2016-02-21 10:00:00'
答案 1 :(得分:0)
试试这个
Select Participantsids
from Schedule
where fromtime between '2016-02-21 10:00:00' and '2016-02-21 13:00:00'
and totime between '2016-02-21 10:00:00' and '2016-02-21 13:00:00';