select t1.* from A t1 ,A t2
where t1.id = t2.id-1 and datediff(dd,t2.D,t1.D) > 90

解决方案 »

  1.   

    select a.* from 表 a where ( select datediff(day,D,a.D) from 表  where id=a.id-1)>90
      

  2.   


    select t1.* from A t1 ,A t2
    where t1.id = t2.id+1 and datediff(dd,t2.D,t1.D) > 90
      

  3.   

    如果ID 不边续
    select t2.*
    from A t1 ,A t2
    where t1.id=(select top 1 id from t1 where id<=t2.id order by id)
          and datediff(day,t1.D,t2.D) > 90
      

  4.   

    如果ID 不边续,改一点
    select t2.*
    from A t1 ,A t2
    where t1.id=(select top 1 id from t1 where id<t2.id order by id)
          and datediff(day,t1.D,t2.D) > 90
      

  5.   

    select 
        t.* 
    from 
        A t 
    where 
        exists(select 1 from A where id=(t.id-1) and datediff(d,D,t.D)>90)
      

  6.   

    select id
    from 表 a
    where a.d - (select top 1 d from 表 where d < a.d order by d desc) > 90
      

  7.   

    select *
    from A表 T
    where datediff(day,(select max(D) from A表 where D < T.D),D) > 90