Oracle 删除重复数据的几种方法

去重
第一种:distinct
create table tmp_t3 as select distinct * from t3;
drop table t3;
alter table tmp_t2 rename to t3;
-- 第二种,用rowid
delete from t2
    where rowid <>( select min(rowid)
                     from t2 b
                     where b.c1 = t2.c1
                       and b.c2 = t2.c2 )
 
---第三种, 用rowid + group by 的方法
delete from T2
    where rowid not in (select min(rowid)
    from t2 group by c1,c2 );
 
delete from t2 
where not exists (select 1 from (select min(rowid) rid from t2 group by c1,c2) b where b.rid=t2.rowid)
 
---第四种, 用分析函数
delete from t2 where rowid in 
(select b.rd from 
(select rowid rd,row_number() over(partition by c1,c2 order by c1) rn 
from t2) b 
where b.rn > 1);

转载于:https://www.cnblogs.com/liang545621/p/9407505.html

你可能感兴趣的:(Oracle 删除重复数据的几种方法)