SQL重复记录查询常用语句

1、查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断
select * from people
where peopleId in (select   peopleId from   people group by   peopleId having count
(peopleId) > 1)
2、删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有rowid最小的记录
delete from people
where peopleId in (select   peopleId from people group by   peopleId   having count
(peopleId) > 1)
and rowid not in (select min(rowid) from   people group by peopleId having count(peopleId
)>1)
3、查找表中多余的重复记录(多个字段)
select * from vitae a
where (a.peopleId,a.seq) in   (select peopleId,seq from vitae group by peopleId,seq having
count(*) > 1)
4、删除表中多余的重复记录(多个字段),只留有rowid最小的记录
delete from vitae a
where (a.peopleId,a.seq) in   (select peopleId,seq from vitae group by peopleId,seq having
count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
5、查找表中多余的重复记录(多个字段),不包含rowid最小的记录
select * from vitae a
where (a.peopleId,a.seq) in   (select peopleId,seq from vitae group by peopleId,seq having
count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)

原文地址:http://plat.delit.cn/thread-77-1-2.html

转载请注明出处:

撰写人:度量科技www.delit.cn

时间: 2024-10-19 02:43:55

SQL重复记录查询常用语句的相关文章

SQL重复记录查询

sql语句: 1.Select COUNT(distinct ann_id) from dmdb.t_bond_ann_att_info where last_update_time >= '2018-03-09 14:00:00'; 2.Select COUNT(id) from dmdb.t_bond_ann_info where create_time >= '2018-03-09 14:00:00'; 3.Select a.* from dmdb.t_bond_ann_info a w

SQL重复记录查询(转载)

(一) 1.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断 select * from people where peopleId in (select  peopleId  from  people  group  by  peopleId  having  count(peopleId) > 1) 例二: select * from testtable where numeber in (select number from people group by numb

收藏:SQL重复记录查询 .

来自:http://blog.csdn.net/chinmo/article/details/2184020 1.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断select * from peoplewhere peopleId in (select   peopleId  from   people  group  by   peopleId  having  count(peopleId) > 1)2.删除表中多余的重复记录,重复记录是根据单个字段(peopleId

SQL重复记录查询-count与group by having结合查询重复记录

查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断select * from peoplewhere peopleId in (select  peopleId  from  people  group  by  peopleId  having  count(peopleId) > 1) 例如: select * from testtable where numeber in (select number from people group by number havin

SQl重复记录查询的几种方法

1.查找表中重复记录,根据单个字段来判断 Select * from tableA where peopleId in(select peopleId from tableA group by peopleI having count (peopleId)>1) 2.查找表中重复记录,根据多个字段判断 Select * from tableA as A where (A.peopleId,A.sew) in (select peopleId,seq from tableA group by pe

SQL某一表中重复某一字段重复记录查询与处理

1.查询出重复记录  select 重复记录字段 form  数据表 group by  重复记录字段 having count(重复记录字段)>1 2.重复记录只显示一条ID值最小或最大的记录 select   id,* from   数据表 where houseno (select 重复记录字段 form 数据表 group by 重复记录 字段 having count(重复记录字段)>1 ) 这样把houseno重复的的ID值全部显示出,那么我们如何只显示一条id最小或最大的记录呢?

SQL Server 数据库部分常用语句小结

1. 查询某存储过程的访问情况 SELECT TOP 1000 db_name(d.database_id) as DBName, s.name as 存储名字, s.type_desc as 存储类型, d.cached_time as SP添加到缓存的时间, d.last_execution_time AS 上次执行SP的时间, d.last_elapsed_time as [上次执行SP所用的时间(微秒)], d.total_elapsed_time [完成此SP的执行所用的总时间(微秒)

oracle数据库查询常用语句

1.查询SCOTT表中有多少表,并显示表的一些描述select * from all_tables WHERE owner='SCOTT' ; 2.查询oracle数据库版本select * from v$version; select version from v$instance; select version FROM Product_component_version;

mysql 多个字段重复记录查询

select * from productstockquantity t where (select count(1) from productstockquantity where t.CombinationId = CombinationId AND t.StoreFrontId = StoreFrontId)>1 ORDER BY t.CombinationI