select a form taba
1990/1/7 上午 08:00:00
1990/1/1 上午 08:00:00
1990/1/1 上午 08:00:00
1990/1/2 上午 08:00:00
1990/1/5 上午 08:00:00
1990/1/8 上午 08:00:00
1990/1/9 上午 08:00:00
1990/1/3 上午 08:00:00
1990/1/4 上午 08:00:00
1990/1/5 上午 08:00:00
1990/1/6 上午 08:00:00
1990/1/7 上午 08:00:00
1990/1/8 上午 08:00:00
1990/1/9 上午 08:00:00
1990/1/3 上午 08:22:00
1990/1/4 上午 08:33:00
1990/1/5 上午 08:44:00
1990/1/6 上午 08:56:00
1990/1/7 上午 08:10:00
1990/1/8 上午 08:10:00
1990/1/9 上午 08:21:00
查询的条件是  显示出连续7天并且时间相同的数据  得到的结果是
1990/1/3 上午 08:00:00
1990/1/4 上午 08:00:00
1990/1/5 上午 08:00:00
1990/1/6 上午 08:00:00
1990/1/7 上午 08:00:00
1990/1/8 上午 08:00:00
1990/1/9 上午 08:00:00希望大家帮帮忙  这个需要写循环~~~ 

解决方案 »

  1.   

    --> 测试数据: #T
    if object_id('tempdb.dbo.#T') is not null drop table #T
    create table #T (a datetime)
    insert into #T
    select '1990/1/7 08:00:00' union all
    select '1990/1/1 08:00:00' union all
    select '1990/1/1 08:00:00' union all
    select '1990/1/2 08:00:00' union all
    select '1990/1/5 08:00:00' union all
    select '1990/1/8 08:00:00' union all
    select '1990/1/9 08:00:00' union all
    select '1990/1/3 08:00:00' union all
    select '1990/1/4 08:00:00' union all
    select '1990/1/5 08:00:00' union all
    select '1990/1/6 08:00:00' union all
    select '1990/1/7 08:00:00' union all
    select '1990/1/8 08:00:00' union all
    select '1990/1/9 08:00:00' union all
    select '1990/1/3 08:22:00' union all
    select '1990/1/4 08:33:00' union all
    select '1990/1/5 08:44:00' union all
    select '1990/1/6 08:56:00' union all
    select '1990/1/7 08:10:00' union all
    select '1990/1/8 08:10:00' union all
    select '1990/1/9 08:21:00';if object_id('tempdb.dbo.#') is not null drop table #
    select id=cast(null as int),* into # from #T;declare @a datetime,@id int
    set @id=0
    update # set id=@id,@id=case when dateadd(day,1,@a)=a then @id else @id+1 end, @a=aselect a from # as t where (select count(1) from # where id=t.id)=7/*
    a
    -----------------------
    1990-01-03 08:00:00.000
    1990-01-04 08:00:00.000
    1990-01-05 08:00:00.000
    1990-01-06 08:00:00.000
    1990-01-07 08:00:00.000
    1990-01-08 08:00:00.000
    1990-01-09 08:00:00.000
    */