TO:楼主想要的结果是否有问题?
9:21 9:24  --这一行间隔超过5分钟吗?

解决方案 »

  1.   

    指的是连续2条记录时间超过5分钟。比如9:10 9:21超过5分钟,9:24 9:30超过5分钟。
    最后得到的
    9:21 9:24分别是上下限
      

  2.   


    declare @tb table(t  datetime)
    declare @tb2 table(t1  datetime,t2  datetime)
    insert @tb values('9:05')
    insert @tb values('9:06')
    insert @tb values('9:10')
    insert @tb values('9:21')
    insert @tb values('9:22')
    insert @tb values('9:24')
    insert @tb values('9:30')
    insert @tb values('9:31')insert into @tb2
    select * from @tb a,@tb b where a.t<b.t and  datediff(minute,a.t,b.t)<=5
    delete a from @tb2 a,@tb2 b where a.t1>=b.t1 and a.t2<=b.t2 and (not (a.t1=b.t1 and a.t2=b.t2)) select * from @tb2t1                      t2
    ----------------------- -----------------------
    1900-01-01 09:05:00.000 1900-01-01 09:10:00.000
    1900-01-01 09:21:00.000 1900-01-01 09:24:00.000
    1900-01-01 09:30:00.000 1900-01-01 09:31:00.000(3 行受影响)