Mysql 其他时间范围内的时间范围
Mysql time range in other time range
大家好,抱歉我的英语不好...
我必须 select 小时范围内的时间不包括在其他时间范围内...
例如,这是 table
DATE | Time_from | Time_to | Hour
01/01/2015 10:00 18:00 8
02/01/2015 08:00 20:00 12
02/01/2015 16:00 19:00 3
对于日期 02/01/2015,我必须只获取带有 12 小时的第 2 行,因为第 3 行的时间范围包含在第 2 行中...
希望我解释的很好...
谢谢
像这样
select a.date
from table a
where not exists (select b.date from table b
where a.date = b.date and
((a.Time_from >= b.Time_from and a.Time_from <= b.Time_to) or
(a.Time_to >= b.Time_from and a.Time_to <= b.Time_to))
编辑
您还需要通过使用唯一 id
添加一些东西,从 table b
中排除 table a
中正在处理的行
and a.uniqueid <> b.uniqeid
大家好,抱歉我的英语不好...
我必须 select 小时范围内的时间不包括在其他时间范围内... 例如,这是 table
DATE | Time_from | Time_to | Hour
01/01/2015 10:00 18:00 8
02/01/2015 08:00 20:00 12
02/01/2015 16:00 19:00 3
对于日期 02/01/2015,我必须只获取带有 12 小时的第 2 行,因为第 3 行的时间范围包含在第 2 行中...
希望我解释的很好...
谢谢
像这样
select a.date
from table a
where not exists (select b.date from table b
where a.date = b.date and
((a.Time_from >= b.Time_from and a.Time_from <= b.Time_to) or
(a.Time_to >= b.Time_from and a.Time_to <= b.Time_to))
编辑 您还需要通过使用唯一 id
添加一些东西,从 tableb
中排除 table a
中正在处理的行
and a.uniqueid <> b.uniqeid