在sql server中显示重复记录 [英] To display the duplicate records in sql server

查看:195
本文介绍了在sql server中显示重复记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 WorkingGroupSchoolContact 的表格,其中包含SchoolID和 ContactID 字段。

现在我们在 ContactID 字段中有相当多的重复条目。对于相同的 SchoolID ,我们可以有 ContactID 的重复条目,但两个或更多相同的 ContactID 应该存在不同的 SchoolID 。现在我必须根据条件过滤数据。任何人都可以帮我执行此操作。

I have a table named "WorkingGroupSchoolContact" with fields "SchoolID" and "ContactID".
Now we have quite number of duplicate entries in the field "ContactID". We can have duplicate entries of the "ContactID" for the same "SchoolID" but the same "ContactID" should be present for two or more different "SchoolID". Now I have to filter data based on the condition. Can anyone please help me to perform this operation.

推荐答案

您好,



请尝试以下查询:



Hello,

Please try below query:

select ContactID,SchoolID,COUNT(ContactID) as DuplicateNumbers from WorkingGroupSchoolContact
group by ContactID,SchoolID
Having COUNT(ContactID) > 1





此查询将返回组合中的所有重复记录ContactID和SchoolID。



如果您对此有任何疑虑或疑问或者我遗失了某些内容,请与我们联系。





谢谢



This query will return all the duplicate records in the combination of ContactID and SchoolID.

Please let me know if you have any concern or query on this or if I am missing something.


Thanks


这篇关于在sql server中显示重复记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆