id        f2      f3    f4
1 保险费 锁定 4
1 保险费 4
3 保险费 4
3 保险费 4
如上表,字段 id  f2  f3   f4
如果同一个id中任意一条记录f3字段包含f3,则此id的所有记录被过滤掉
结果得到id为3的记录
请问如何用1句sql得出此结果

解决方案 »

  1.   

    select * from t1
    where t1.id not in
    select id
    from t1
    where t1.id!=nullsql忘得差不多了
      

  2.   

    select 
      *
    from 
      tb t
    where
      not exists(select 1 from tb where id=t.id and len(isnull(f3,''))>0)
    select 
      * 
    from 
      tb
    where 
      id not in(select id from tb where len(f3)>0)
      

  3.   

    select * from 如上表 a 
    where not exists (select id from 如上表 where id=a.id and f3 is not null)