Duplicate Emails

题目

Write a SQL query to find all duplicate emails in a table namedPerson.

+----+---------+
| 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.

SQL Schema:

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]');

思路分析

这道题应该是首先利用groupBy function将相同的email组合起来,然后filter出COUNT数大于1的email:

# Write your MySQL query statement below
SELECT Email
FROM Person
GROUP BY Email
HAVING COUNT(*) > 1;

results matching ""

    No results matching ""