Count of distinct rows with duplicate email IDs
如何在SQL中获取具有重复电子邮件ID的不同行的计数?
1 2 3 4 5 6 7 8 | ID NAME EMAIL 1 John asd@asd.com 2 Sam asd@asd.com 4 Bob bob@asd.com 5 Tom asd@asd.com 6 Rob bob@asd.com 7 Tic tic@asd.com 8 Dad dad@asd.com |
查询应该返回2。
[email protected]和[email protected]是重复的
1 2 3 4 5 | SELECT COUNT(*) FROM Users GROUP BY EMail HAVING ( COUNT(EMAIL) > 1 ) |
此查询返回一些奇怪的结果。
谢谢
行数:
1 2 3 4 5 | SELECT SUM(cnt) FROM (SELECT COUNT(*) AS cnt FROM Users GROUP BY email HAVING COUNT(*) > 1) T |
电子邮件数量:
1 2 3 4 5 | SELECT COUNT(*) FROM (SELECT COUNT(*) AS cnt FROM Users GROUP BY email HAVING COUNT(*) > 1) T |
两个都是:
1 2 3 4 5 | SELECT COUNT(*) AS COUNT_EMAIL SUM(cnt) AS COUNT_ROWS FROM (SELECT COUNT(*) AS cnt FROM Users GROUP BY email HAVING COUNT(*) > 1) T |
以上应该适用于SQL Server和Oracle。