https://leetcode.com/problems/duplicate-emails/
Duplicate Emails - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
Table: Person
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| id | int |
| email | varchar |
+-------------+---------+
id is the primary key column for this table.
Each row of this table contains an email. The emails will not contain uppercase letters.
Write an SQL query to report all the duplicate emails.
Return the result table in any order.
The query result format is in the following example.
Example 1:
Input:
Person table:
+----+---------+
| id | email |
+----+---------+
| 1 | a@b.com |
| 2 | c@d.com |
| 3 | a@b.com |
+----+---------+
Output:
+---------+
| Email |
+---------+
| a@b.com |
+---------+
Explanation: a@b.com is repeated two times.
SELECT email
FROM Person
GROUP BY email
HAVING COUNT(*) >= 2
email이 2개 이상나오는 데이터를 출력하는 쿼리이다. 값이 중복되는 데이터를 찾는 건데 GROUP BY를 이용한다.
GROUP BY email과 COUNT(*)를 사용하면 email별로 데이터의 개수가 집계된다.
HAVING COUNT(*) >= 2를 이용해 값이 2개이상 반복되는 데이터만 출력한다.
Delete Duplicate Emails(Leet Code) (0) | 2022.08.02 |
---|---|
Swap Salary(LeetCode) (0) | 2022.08.02 |
Symmetric Pairs(HackerRank) (0) | 2022.07.20 |
Rising Temperature(LeetCode) (0) | 2022.07.20 |
Employees Earning More Than Their Managers(LeetCode) (0) | 2022.07.20 |
댓글 영역