我有一个值表,其有效性从开始日期开始,如下所示:
select x.*
into #t
from
(select 15 as value, '2012.05.20' as start-datedate
union
select 15, '2012.06.20'
union
select 15, '2012.07.20'
union
select 16, '2012.08.20'
union
select 17, '2012.09.20'
union
select 15, '2012.11.20'
union
select 17, '2012.12.20'
) x
所以表看起来像这样:
select * from #t order by date
value start-date
-----------------------------
15 2012.05.20
15 2012.06.20
15 2012.07.20
16 2012.08.20
17 2012.09.20
15 2012.11.20
17 2012.12.20
我的问题是如何制作每个值都有效的时间段表。它应该如下所示:
value start_date end_date
15 2012.05.20 2012.08.20
16 2012.08.20 2012.09.20
17 2012.09.20 2012.11.20
15 2012.11.20 2012.12.20
17 2012.12.20
谢谢!