码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2015-01-28 14:32:03      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:

删除表重复数据 (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);

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

标签:

原文地址:http://www.cnblogs.com/uzipi/p/4255694.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!