如果为空可以用null来判断,那怎么样查询连续为空的记录啊?
如果有两列,ID,DATE,想找出DATE连续两天为空的记录 

解决方案 »

  1.   


    select * from T a where (select count(1) from T where abs(ID-a.ID)=1 and [Date] is null)>1
      

  2.   

    --用lead
    select 
    *
    from 
    (select 
    *,
    case when Date is null then 1 else 0 end as col1,
    case when lead(Date)over(order by ID)is null then 1 else 0 end col2
    from 
    T)TT
    where
    Col1=COl2 and Col1=1
      

  3.   

    对,用lead分析函数
    FYI:http://topic.csdn.net/u/20071019/01/e79e1215-f2d8-4179-a310-606ad5103649.html