找到了三个删除重复数据的方法,我只会第一种。
下边就把三种方法都列出来
我自己建了一个简单的表test
ID SQL
1 100 200802
2 100 200802
3 100 200802
4 100 200802
5 100 200802
第一种:
delete from test a where a.rowid <>
(
select max(rowid) from test b where a.id=b.id and a.sql=b.sql
);
第二种:
delete from test where rowid in
(
select rid from
(
select rowid rid,row_number() over(partition by id,sql order by rowid) rn from test
)where rn <>1
);
第三种:
create table test2 as
(
select id,sql from
(
select id,sql,row_number() over(partition by id,sql order by rowid) rn from test t
)where rn=1
);
truncate table test;
insert into test2 values(select * from test2);
drop table test2;
据说第二种方法的效率非常高。对于大数据量来说,第一种方法如果需要N个小时,那么方法二只需要半分钟。
第三种方法的第一步效率等同于方法二,不过对于后面的insert操作我持怀疑态度。