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...
--数据库的使用过程中由于程序方面的问题有时候会碰到重复数据,重复数据导致了数据库部分设置不能正确设置…… 方法一declare @max integer,@id integer declare cur_rows cursor local for select 主字段,count(*) from 表名 group by 主字段 having count(*) > 1 open cur_rows fetch cur_rows into @id,@max while @@fetch_status=0 begin select @max = @max -1 set rowcount @max delete from 表名 where 主字段 = @id fe...
我们经常在数据库中有重复的记录这时候我们希望删除那些重复的记录 你不要告诉我你是一条条手动删除的哈: select distinct * into newtable form tablename drop table tablename select * into table from newtable drop table newtable 思路好了就好做.
* 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 co...
代码如下:
select * from peoplewhere 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 ...
--查出表中有重复的id的记录,并计算相同id的数量select id,count(id) from @table group by id having(count(id)>1)
其中,group by id,是按id字段分组查询:
select id,count(id) from @table group by id
可以得到各不同id的数量合计
having(count(id)>1)判断数量大于1,也就是有重复id的记录
您可能感兴趣的文章:SQL 查询和删除重复字段数据的方法SQL重复记录查询的几种方法SQL语句实现删除重复记录并只保留一条SQL重复记...