Skip to main content

182. Duplicate Emails

Giới thiệu bài toán

Chi tiết: https://leetcode.com/problems/duplicate-emails

Table: Person

Column NameType
idint
emailvarchar
  • id is the primary key (column with unique values) for this table.
  • Each row of this table contains an email. The emails will not contain uppercase letters.
Yêu cầu

Write a solution to report all the duplicate emails. Note that it's guaranteed that the email field is not NULL.

Return the result table in any order. The result format is in the following example.

Example 1:

  • Input: Person table:
idemail
1a@b.com
2c@d.com
3a@b.com
  • Output:
Email
a@b.com
  • Explanation: a@b.com is repeated two times.

Giải quyết bài toán

SELECT email 
FROM Person
GROUP BY email
HAVING COUNT(id) > 1;

Tham khảo: https://leetcode.com/submissions/detail/1039091405/