oracle 删除重复数据

我要删除2015-10-19日的wdinfo字段重复的数据

(1)先查出数据

SELECT id, wdinfo
FROM BUSINISS
where starttime = to_date('2015-10-19', 'yyyy-mm-dd')
order by id desc

(2)查出这些重复数据的重复次数

select min(id),count(*)  from (SELECT id, wdinfo
FROM BUSINISS
where starttime = to_date('2015-10-19', 'yyyy-mm-dd')
order by id desc) group by wdinfo 

(3)最后留下最小id的数据,其他的重复数据删除

delete from businiss where id not in (select min(id) from (SELECT id, wdinfo

FROM BUSINISS
where starttime = to_date('2015-10-19', 'yyyy-mm-dd')
order by id desc) group by wdinfo )

posted @ 2015-10-20 16:07  萌萌,加油  阅读(362)  评论(0编辑  收藏  举报