表T1字段 A    字段Baa       bb
af       ff
rt       we
ff       gg
ff       gg
--------------------------
要显示
ff       gg  select a,b from t1 group by a,b having count(*)>1 这样可以查出来
用表连接的方式怎么查?

解决方案 »

  1.   

    select * from t1 a where exists
    (select 1 from t1 b where b.rowid<>a.rowid and b.a=a.a and b.b=a.b)
    要去重复加上distinct,效率明显低了些
      

  2.   

    还是这样select a,b from t1 group by a,b having count(*)>1 好点吧
      

  3.   

    select a,b from t1 group by a,b having count(*)>1 这样可以查出来这种方式应该是效率最高的
      

  4.   

    select a,b from t1 group by a,b having count(*)>1
    这种方法就很好,为什么还要用表连接呢?
      

  5.   

    select distinct a.a,a.b 
    from t1 a inner join t1 b
    on a.a = b.a
    and a.b=b.b
      

  6.   

    楼上正解,select a,b from t1 group by a,b having count(*)>1 就可以了
      

  7.   

    select a.*
    from
    (
    select t.* ,row_number() over(partition by t.字段 A,t.字段B order by t.字段A desc) rn from t1 t 
    ) a where a.rn=2
    或者 
    select d.*
    from t1 d,
    (
    select max(rowid) 
    from t1 a, t1 b
    where a.字段 A=b.字段 A
    and b.字段 B=b.字段 B
    ) c where d.rowid=c.rowid