【Oracle】去除表中重复的数据
2015-01-28 14:10
357 查看
删除表重复数据 (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);
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学习----去除表中的重复数据
- oracle去除重复, 取最新的第一条数据
- oracle去除重复, 取最新的第一条数据
- oracle查询去除数据重复
- oracle 的 row_number over 去除重复数据
- Oracle去除重复(某一列的值重复),取最新(日期字段最新)的一条数据
- Oracle查询中如何去除查询的重复数据
- 去除数据表中重复行&oracle 替换数据
- oracle 去除重复数据
- oracle去除重复数据
- oracle,把多列同时转成用逗号分割的一行,并去除重复数据
- oracle 批量插入时,如何去除重复数据
- Oracle去除重复数据的方法
- Oracle去除表重复数据
- oracle中sql去除重复数据
- Oracle 中去除重复数据
- oracle 重复数据去除
- Oracle 中如何删除重复数据
- 删除oracle中完全重复的数据
- Oracle不同行的某列字符串相加,去除重复值