如: 有A表, A表中有字段X.
问题: 写SQL删除A表中有字段X值重复的记录

解决方案 »

  1.   

    delete * from where x not in (select min(x) from A )
      

  2.   

    delete from A a where a.rowid > (select min(x.rowid) from A b where a.x = b.x)
      

  3.   


    min(x.rowid)写错了,应该是 min(b.rowid)
      

  4.   


    --是这个意思吧
    13:31:03 SQL> select * from tb2;NAME                 TYPE
    -------------------- ----------
    wkc168               dbaa
    wkc168               168
    wkc                  18
    wkc                  28
    ycm                  21  1* delete from tb2 a where type in (select max(type) from tb2 group by name having count(*)>1)
    13:33:05 SQL> /已删除2行。13:33:06 SQL> select * from tb2;NAME                 TYPE
    -------------------- ----------
    wkc168               168
    wkc                  18
    ycm                  21
      

  5.   


    --2
    delete from tb a where exists(select 1 from tb where a.x=x and a.col1>col1);
    --col1为其他的列
      

  6.   

     
    delete from A where rowid in (
       select row_id from (
          select rowid row_id,row_number() over (partition by X order by rowid ) rn
       ) where rn <> 1
    );
      

  7.   


    delete from tb2 a where type in (select max(type) from tb2 group by name having count(*)>1)
    那种方式,要速度快点?