A         B
20        1
21        2
21        3
20        4
21        4
我现在要把4取出来,我这里重复的倍数可能是2倍以上的,是外界的一个不定值,所以好像不好用count

解决方案 »

  1.   


    SQL> select * from tbl where b in(select b from tbl group by b having count(b)>1);         A          B
    ---------- ----------
            20          4
            21          4SQL>
      

  2.   


    SQL> select b from tbl group by b having count(b)>1;         B
    ----------
             4SQL>
      

  3.   

    delete from 
           (select * from tbl 
            where b in(select b from tbl group by b having count(b)>1));
      

  4.   

    不能直接写having count(b)>1,也可能是count(b)>2、3,这个值是外界不定的
      

  5.   

    delete from 
    (
      select * from tbl A
            where rowid = (select max(rowid) from tbl where A.b = b )
    )
      

  6.   

    select b
    from tablename
    where a=20
    intersect
    select b
    from tablename
    where a-21;select b
    from tablename
    where a=20
    intersect
    select b
    from tablename
    where a=21
    intersect
    select b
    from tablename
    where a=22;