客户编号  日期       单号   子单号
001      2011-2-5   KH001   KHGts001
001      2011-5-5   KH001   KHGts001
001      2011-5-5   KH001   KHGts002
002      2000-1-1   KH004   KHGts004
我要实现的是根据客户编号分组查询,若当前日期大于日期 即超期,在一笔单号中有一笔子单号超期这笔单号就算一笔超期,请问用SQL怎么实现 最好不要用Declare

解决方案 »

  1.   

    select *
    from tb t
    where exists(select 1 from tb where 客户编号=t.客户编号 and getdate()>日期)
      

  2.   

    select *
    from tb t
    where exists(select 1
                 from tb 
                 where 客户编号=t.客户编号 and getdate()>t.日期)
      

  3.   

    select *
    from tb t
    where exists(select 1 from tb where 客户编号=t.客户编号 and getdate()>日期)
      

  4.   

    select *
    from tb t
    where exists(select 1 from tb where 客户编号=t.客户编号 and getdate()>日期)