时间重叠度的问题!j叔叔、leimin、邹建、马可、CrazyFor等高手帮我呀!
题目如下:
create table #a(id int identity(1,1),date1 datetime,date2 datetime)
insert #a select '2004-02-29 16:45:00','2004-02-29 20:45:00'
union all select '2004-02-29 18:45:00','2004-02-29 22:45:00'
union all select '2004-03-01 10:45:00','2004-03-01 13:45:00'
union all select '2004-03-01 13:45:00','2004-03-01 16:45:00'
union all select '2004-03-01 13:47:00','2004-03-01 14:25:00'
union all select '2004-03-01 16:45:00','2004-03-01 19:15:00'
union all select '2004-03-01 17:45:00','2004-03-01 18:55:00'
union all select '2004-03-01 18:45:00','2004-03-01 21:45:00'
select *from #a
我现在要找出时间上重叠超过1个小时的所有记录!
比如第1、2条:一个是从16:45---20:45,第二条是从18:45---22:45时间上重叠了2个小时,所以这两条都要取出,其它的也是一样的规则!
date2-date1小于1小时的不用考虑,如第5条。可以先删除该条,记录是按date1排序的!
所以最终的结果要为:
id date1 date2
----------- --------------------------- ---------------------------
1 2004-02-29 16:45:00.000 2004-02-29 20:45:00.000
2 2004-02-29 18:45:00.000 2004-02-29 22:45:00.000
6 2004-03-01 16:45:00.000 2004-03-01 19:15:00.000
7 2004-03-01 17:45:00.000 2004-03-01 18:55:00.000