oracle如何查重复数据并显示出来?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了oracle如何查重复数据并显示出来?相关的知识,希望对你有一定的参考价值。
参考技术A SELECT *\\x0d\\x0aFROM t_info a\\x0d\\x0aWHERE ((SELECT COUNT(*)\\x0d\\x0a FROM t_info\\x0d\\x0a WHERE Title = a.Title) > 1)\\x0d\\x0aORDER BY Title DESC\\x0d\\x0a一。查找重复记录\\x0d\\x0a1。查找全部重复记录\\x0d\\x0aSelect * From 表 Where 重复字段 In (Select 重复字段 From 表 Group By 重复字段 Having Count(*)>1)\\x0d\\x0a2。过滤重复记录(只显示一条)\\x0d\\x0aSelect * From HZT Where ID In (Select Max(ID) From HZT Group By Title)\\x0d\\x0a注:此处显示ID最大一条记录\\x0d\\x0a二。删除重复记录\\x0d\\x0a\\x0d\\x0a1。删除全部重复记录(慎用)\\x0d\\x0aDelete 表 Where 重复字段 In (Select 重复字段 From 表 Group By 重复字段 Having Count(*)>1)\\x0d\\x0a2。保留一条(这个应该是大多数人所需要的 ^_^)\\x0d\\x0aDelete HZT Where ID Not In (Select Max(ID) From HZT Group By Title)\\x0d\\x0a注:此处保留ID最大一条记录\\x0d\\x0a1、查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断\\x0d\\x0aselect * from people\\x0d\\x0awhere peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)\\x0d\\x0a \\x0d\\x0a2、删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有rowid最小的记录\\x0d\\x0adelete from people\\x0d\\x0awhere peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)\\x0d\\x0aand rowid not in (select min(rowid) from people group by peopleId having count(peopleId )>1)\\x0d\\x0a \\x0d\\x0a3、查找表中多余的重复记录(多个字段)\\x0d\\x0aselect * from vitae a\\x0d\\x0awhere (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)\\x0d\\x0a \\x0d\\x0a4、删除表中多余的重复记录(多个字段),只留有rowid最小的记录\\x0d\\x0adelete from vitae a\\x0d\\x0awhere (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)\\x0d\\x0aand rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)\\x0d\\x0a \\x0d\\x0a5、查找表中多余的重复记录(多个字段),不包含rowid最小的记录\\x0d\\x0aselect * from vitae a\\x0d\\x0awhere (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)\\x0d\\x0aand rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)\\x0d\\x0a\\x0d\\x0a补充:\\x0d\\x0a有两个以上的重复记录,一是完全重复的记录,也即所有字段均重复的记录,二是部分关键字段重复的记录,比如Name字段重复,而其他字段不一定重复或都重复可以忽略。\\x0d\\x0a \\x0d\\x0a1、对于第一种重复,比较容易解决,使用\\x0d\\x0aselect distinct * from tableName\\x0d\\x0a \\x0d\\x0a就可以得到无重复记录的结果集。\\x0d\\x0a \\x0d\\x0a如果该表需要删除重复的记录(重复记录保留1条),可以按以下方法删除\\x0d\\x0aselect distinct * into #Tmp from tableName\\x0d\\x0adrop table tableName\\x0d\\x0aselect * into tableName from #Tmp\\x0d\\x0adrop table #Tmp\\x0d\\x0a \\x0d\\x0a发生这种重复的原因是表设计不周产生的,增加唯一索引列即可解决。\\x0d\\x0a \\x0d\\x0a2、这类重复问题通常要求保留重复记录中的第一条记录,操作方法如下\\x0d\\x0a \\x0d\\x0a假设有重复的字段为Name,Address,要求得到这两个字段唯一的结果集\\x0d\\x0aselect identity(int,1,1) as autoID, * into #Tmp from tableName\\x0d\\x0aselect min(autoID) as autoID into #Tmp2 from #Tmp group by Name,autoID\\x0d\\x0aselect * from #Tmp where autoID in(select autoID from #tmp2)oracle查询的数据如何去重显示?
如图中我查询到的数据,前七行都是重复数据,如何能将前七行数据合并显示,后三行数据跟随在其后,即一个产品对应多个库房显示
参考技术A以上是关于oracle如何查重复数据并显示出来?的主要内容,如果未能解决你的问题,请参考以下文章