标签:
删除表重复数据 (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);
标签:
原文地址:http://www.cnblogs.com/uzipi/p/4255694.html