日期:2014-05-16  浏览次数:20469 次

mssql存储过程,如何过滤数据库中时间段重复的数据,获得实际时间?
如:id                           begintime                          endtime
       1                             2014-04-18 10:00:00       2014-04-18 10:50:00
       1                             2014-04-18 10:30:00       2014-04-18 11:00:00
       1                             2014-04-18 10:10:00       2014-04-18 12:30:00
       1                             2014-04-18 10:10:00       2014-04-18 12:30:00
       1                             2014-04-18 11:30:00       2014-04-18 12:00:00
       1                             2014-04-18 11:30:00       2014-04-18 12:00:00

比如像上面这样的一组数据,如何去除他的重复时间段,获得ID=1消耗的总时间分数?

感谢大虾帮忙!!!
------解决方案--------------------
不好意思,有点忙,写了一个,有点复杂。。
--> 测试数据[huang]
if object_id('[huang]') is not null drop table [huang]
go 
create table [huang]([id] int,[begintime] datetime,[endtime] datetime)
insert [huang]
select 1,'2014-04-18 10:00:00','2014-04-18 10:50:00' union all
select 1,'2014-04-18 10:30:00','2014-04-18 11:00:00' union all
select 1,'2014-04-18 10:10:00','2014-04-18 12:30:00' union all
select 1,'2014-04-18 10:10:00','2014-04-18 12:30:00' union all
select 1,'2014-04-18 11:30:00','2014-04-18 12:00:00' union all
select 1,'2014-04-18 11:30:00','2014-04-18 12:00:00' union all
select 1,'2014-04-18 15:30:00','2014-04-18 16:00:00'
union all
select 2,'2014-04-18 15:30:00','2014-04-18 16:00:00'
UNION ALL 
select 2,'2014-04-18 10:00:00','2014-04-18 10:50:00' union all
select 2,'2014-04-18 10:30:00','2014-04-18 11:00:00' union all
select 2,'2014-04-18 10:10:00','2014-04-18 12:30:00' union all
select 2,'2014-04-18 10:10:00','2014-04-18 12:30:00' union all
select 2,'2014-04-18 11:30:00','2014-04-18 12:00:00' union all
select 2,'2014-04-18 11:30:00','2014-04-18