我需要运行一条select语句,以返回列值不唯一的所有行(例如EmailAddress)。
例如,如果表如下所示:
CustomerName EmailAddress
Aaron [email protected]
Christy [email protected]
Jason [email protected]
Eric [email protected]
John [email protected]
我需要查询返回:
Aaron [email protected]
Christy [email protected]
John [email protected]
我已经阅读了许多帖子,并尝试了不同的查询,但没有成功。我认为应该工作的查询如下。有人可以提出替代方案或告诉我我的查询可能出什么问题吗?
select EmailAddress, CustomerName from Customers
group by EmailAddress, CustomerName
having COUNT(distinct(EmailAddress)) > 1
最佳答案
这比EXISTS
方法快得多:
SELECT [EmailAddress], [CustomerName] FROM [Customers] WHERE [EmailAddress] IN
(SELECT [EmailAddress] FROM [Customers] GROUP BY [EmailAddress] HAVING COUNT(*) > 1)
关于sql - 如何选择不区分列值的每一行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13146304/