oracle 删除重复数据的方法

1.单个字段

DELETE from 表 WHERE (id) IN ( SELECT id FROM 表 GROUP BY id HAVING COUNT(id) > 1) AND ROWID NOT IN (SELECT MIN(ROWID) FROM 表
GROUP BY id HAVING COUNT(*) > 1);

例子:删除周次为43且ryid重复的数据

delete from bc_ry_his where c_zc=43 and ryid in(select ryid from bc_ry_his group by ryid having count(ryid)>1) and rowid not in
(select min(rowid) from bc_ry_his group by ryid having count(*)>1)

2.多个字段

delete from 表 a where (a.Id,a.seq) in (select Id,seq from 表 group by Id,seq having count(*) > 1) and rowid not in (select min(rowid) from 表 group by Id,seq having count(*)>1)

例子:删除周次为43且ryid,bc_xm 重复的数据

delete from bc_ry_his where c_zc=43 and (ryid,bc_xm) in(select ryid,bc_xm from bc_ry_his group by ryid,bc_xm having count(*)>1) and rowid not in
(select min(rowid) from bc_ry_his group by ryid,bc_xm having count(*)>1)