본문 바로가기
MySQL/문제풀이

[LeetCode] 182. Duplicate Emails

by MINNI_ 2021. 3. 22.

1. 문제

 

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

+----+---------+
| Id | Email   |
+----+---------+
| 1  | a@b.com |
| 2  | c@d.com |
| 3  | a@b.com |
+----+---------+

For example, your query should return the following for the above table:

+---------+
| Email   |
+---------+
| a@b.com |
+---------+

Note: All emails are in lowercase.


2. 답

SELECT Email
FROM Person
GrOUP BY Email
HAVING COUNT(Id) != 1

3. KEY POINT

  • 중복된 것 출력 => GROUP BY 하여 COUNT 값이 1이 아닌 것 출력

 

 

leetcode.com/problems/duplicate-emails/

댓글