一张表a
字段:aa,bb,cc,dd,ee,ff,gg,hh
要求:查询有aa字段相同,但bb字段不同的SQL语句。

解决方案 »

  1.   

    select * from a where aa <> bb;
    select * from a where aa != bb;
      

  2.   

    select aa,bb from a
    group by aa,bb
    having count(aa)>1 and count(bb)=1
    试试
      

  3.   

    SQL> select * from t1;
     
            AA         BB         CC
    ---------- ---------- ----------
             1          2          3
             1          3          3
             1          2          3
             2          3          4
             2          3          4
     
    SQL> 
    SQL> select * from t1 a
      2  where exists(select 1 from t1 b where a.aa = b.aa and a.bb != b.bb)
      3  ;
     
            AA         BB         CC
    ---------- ---------- ----------
             1          3          3
             1          2          3
             1          2          3