[SQL] SQL 查出一张表中重复的所有记录

在A表中存在一个字段“AccountId”,而且不同记录之间的“AccountId”值有可能会相同,现在就是需要查询出在该表中的各记录之间,“AccountId”值存在重复的项,这里count记录该字段重复的记录数(此处只针对该字段是否重复进行查询);
Select AccountId,Count(*) From A Group By AccountId Having Count(*) > 1

如果查询多个字段也相同大则如下:
Select AccountId,Name,Count(*) From A Group By AccountId,Name Having Count(*) > 1

查询出重复的所有记录:

select * from A where AccountId in (select AccountId from A group by AccountId having count(AccountId) > 1)

原文地址:https://www.cnblogs.com/wynlfd/p/5710337.html