请教个SQL

T-Mac-Paul 2016-09-12 05:35:35


如图,这么一张表,我现在想把重复的数据删除了,这个sql应该怎么写
entityTypeId和targetEntityTypeId不是联合主键,两条数据没有任何不同的地方
...全文
132 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
T-Mac-Paul 2016-09-13
  • 打赏
  • 举报
回复
引用 8 楼 ghx287524027 的回复:
[quote=引用 7 楼 ghx287524027 的回复:] rowid去重就可以了,比如: delete from table a where rowid <> (select max(rowid) from table b where a.EntityTypeId = b.EntityTypeId and a.targetEntityTypeId = b.targetEntityTypeId) 7# 大牛的方法也是极好的~
6 # 。。。。。[/quote] 谢谢大神
ghx287524027 2016-09-13
  • 打赏
  • 举报
回复
引用 7 楼 ghx287524027 的回复:
rowid去重就可以了,比如: delete from table a where rowid <> (select max(rowid) from table b where a.EntityTypeId = b.EntityTypeId and a.targetEntityTypeId = b.targetEntityTypeId) 7# 大牛的方法也是极好的~
6 # 。。。。。
ghx287524027 2016-09-13
  • 打赏
  • 举报
回复
rowid去重就可以了,比如: delete from table a where rowid <> (select max(rowid) from table b where a.EntityTypeId = b.EntityTypeId and a.targetEntityTypeId = b.targetEntityTypeId) 7# 大牛的方法也是极好的~
jdsnhan 2016-09-13
  • 打赏
  • 举报
回复
delete from table a where (a.entityTypeId,a.targetEntityTypeId) in (select entityTypeId,targetEntityTypeId from table group by entityTypeId,targetEntityTypeId having count(*) > 1) and rowid not in (select min(rowid) from table group by entityTypeId,targetEntityTypeId having count(*)>1)
IceIsabel 2016-09-12
  • 打赏
  • 举报
回复
可以用rowid来删除重复项,group by那两个字段,留其中一个rowid的那条就可以
T-Mac-Paul 2016-09-12
  • 打赏
  • 举报
回复
引用 2 楼 ghx287524027 的回复:
[quote=引用 1 楼 ghx287524027 的回复:] 什么样的数据算是重复数据?
所有字段的值都一样的算是重复?[/quote] 恩,最主要还是EntityTypeId和targetEntityTypeId
T-Mac-Paul 2016-09-12
  • 打赏
  • 举报
回复
引用 1 楼 ghx287524027 的回复:
什么样的数据算是重复数据?
entityTypeId+targetEntityTypeId相同的
ghx287524027 2016-09-12
  • 打赏
  • 举报
回复
引用 1 楼 ghx287524027 的回复:
什么样的数据算是重复数据?
所有字段的值都一样的算是重复?
ghx287524027 2016-09-12
  • 打赏
  • 举报
回复
什么样的数据算是重复数据?

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧