A表
ID status
0001 bad
0002 good
0001 good
0002 bad
0003 good
0004 good
0005 good
0001 bad
0003 bad



ID status
004 good
005 good

就是只要一个ID出现的status是有2次以上的状态:bad和good,这个数据就不要了

解决方案 »

  1.   

    select *  from A t where not Exists ( select 1 from A  where ID=t.ID  And status!= t.status)
      

  2.   


    SELECT * from tta a where not exists(select 1 from tta where a.ID=id and a.status<>status)
      

  3.   

    select id,status
    from tb
    group by id
    having count(distinct status)<=1
      

  4.   


    这个还算快,但是这个count(distinct status)效率是不是低啊
    ,这个有点不懂了,为什么不把count(distinct status)<=放在select语句中啊,能否解释以下啊?