Loading

【Oracle】去除表中重复的数据

删除表重复数据 (t1表中有重复数据)
1、使用distinct
create table t2 as select * from t1;
create table tmp_t2 as select distinct * from t2;
drop table t2;alter table tmp_t2 rename to t2(需停业务)

------------------------------------------------------------------------------------
2、使用ROWID

delete from t1
where rowid <>( select min(rowid)
from t1 b
where b.c1 = t1.c1
and b.c2 = t1.c2 )

------------------------------------------------------------------------------------
3、用rowid + group by 的方法
delete from t1
where rowid not in (select min(rowid)
from t1 group by c1,c2 );

------------------------------------------------------------------------------------
4.使用分析函数
delete from t1 where rowid not in
(select b.rd from
(select rowid rd,row_number() over(partition by c1,c2 order by c1) rn
from t1) b
where b.rn = 1);

------------------------------------------------------------------------------------
5.使用EXISTS

delete from t1
where not exists (select 1 from (select min(rowid) rid from t1 group by c1,c2) b where b.rid=t1.rowid);

posted @ 2015-01-28 14:10  uzipi  阅读(907)  评论(0编辑  收藏  举报