if exists(select 1 from tb where ....)
请给出表结构,测试数据,相关算法和需要的结果.谢谢!

解决方案 »

  1.   

    字段   报告号      试验号    收费状态 
       6109-09LB-001 0900002   已收 
       6109-09LB-001 0900001   null 
    select case when if exists(select 1 from tb where 报告号 = t.报告号 and 收费状态 is null) then null else '已收' end,*
    from tb t
      

  2.   


     isnull(收费状态,'')
      

  3.   

    select * from tb 
    where 报告号 not in (select distinct 报告号 from tb where 收费状态 != '已收')
      

  4.   


    select 报告号 from tb a where not exists(select 1 from tb where 报告号=a.报告号 and isnull(收费状态,'')<>'已收' )
      

  5.   

    select 报告号 from tb a where not exists(select 1 from tb where 报告号=a.报告号 and isnull(收费状态,'')<>'已收' )
      

  6.   

    select distinct 报告号 from tb a where not exists(select 1 from tb where 报告号=a.报告号 and isnull(收费状态,'')<>'已收' )
      

  7.   

    select * from table where 报告号 not in ( select 报告号 from table where  收费状态  is null)