tips:
1 代码在sqlserver2005实现,其他数据需要经过修改
2 计算连续时间和连续数字是同一类问题,所以合起来一起说,计算连续时间的时候只不过将时间转换成数字而已
3 此方法相对高效
第一步
构造数据
create table #tmptable(id int identity(1,1),rq smalldatetime)
insert #tmptable values('2010.1.1')
insert #tmptable values('2010.1.2')
insert #tmptable values('2010.1.3')
insert #tmptable values('2010.1.6')
insert #tmptable values('2010.1.7')
insert #tmptable values('2010.1.10')
insert #tmptable values('2010.1.11')
insert #tmptable values('2010.1.12')
insert #tmptable values('2010.1.19')
insert #tmptable values('2010.1.20')
insert #tmptable values('2010.1.22')
insert #tmptable values('2010.1.23')
insert #tmptable values('2010.1.28')
第二步
临时中间表
select id,rq,datediff(d,(select min(rq) from #tmptable),rq)+1 idd into #