LeetCode:182. Duplicate Emails

题目:
Write a SQL query to find all duplicate emails in a table named Person.

+—-+———+
| Id | Email |
+—-+———+
| 1 | [email protected] |
| 2 | [email protected] |
| 3 | [email protected] |
+—-+———+
For example, your query should return the following for the above table:

+———+
| Email |
+———+
| [email protected] |
+———+
Note: All emails are in lowercase.

Answer:
思路:GROUP BYHAVING COUNT用法。

SELECT Email FROM person GROUP BY Email HAVING COUNT(Email) > 1

附表email的sql:

Create table If Not Exists Person (Id int, Email varchar(255));
Truncate table Person;
insert into Person (Id, Email) values ('1', '[email protected]');
insert into Person (Id, Email) values ('2', '[email protected]');
insert into Person (Id, Email) values ('3', '[email protected]');
发布了43 篇原创文章 · 获赞 27 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/SCUTJcfeng/article/details/80010994