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);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM