Oracle删除重复数据(1)
数据库  /  管理员 发布于 3年前   188
creat table tbl_tmp (select distinct* from tbl);truncate table tbl;//清空表记录insert into tbl select * from tbl_tmp;//将临时表中的数据插回来。
delete from tbl where rowid in (select a.rowid from tbl a,tbl b where a.rowid>b.rowid and a.col1=b.col1 and a.col2 = b.col2)
delete from tbl a where rowid not in (select max(b.rowid)from tbl b where a.col1=b.col1 and a.col2 = b.col2);//这里max使用min也可以
delete from tbl a where rowid<(select max(b.rowid)from tbl b where a.col1=b.col1 and a.col2 = b.col2);//这里如果把max换成min的话,前面的where子句中需要把"<"改为">"
delete from tbl where rowid not in (select max(rowid)from tbl t group by t.col1, t.col2);delete from tbl where (col1, col2)in (select col1,col2 from tbl group by col1,col2 having count(*)>1) and rowid not in(select min(rowid) from tbl group by col1,col2 having count(*) >1)
博主 在
2023年国务院办公厅春节放假通知:1月21日起休7天中评论 @ xiaoB 你只管努力,剩下的叫给天意;天若有情天亦老,..xiaoB 在
2023年国务院办公厅春节放假通知:1月21日起休7天中评论 会不会春节放假后又阳一次?..BUG4 在
你翻墙过吗?国内使用vpn翻墙可能会被网警抓,你需了解的事中评论 不是吧?..博主 在
go语言+beego框架中获取get,post请求的所有参数中评论 @ t1 直接在router.go文件中配就ok..Jade 在
如何在MySQL查询中获得当月记录中评论 Dear zongscan.com team, We can skyroc..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号