Problem solving/DataBase
[LeetCode] 182. Duplicate Emails (Oracle)
Young_A
2021. 1. 14. 22:43
LeetCode - Problems - Database - 182. Duplicate Emails
더보기
Given SQL Schema
Create table If Not Exists Person (Id int, Email varchar(255))
Truncate table Person
insert into Person (Id, Email) values ('1', 'a@b.com')
insert into Person (Id, Email) values ('2', 'c@d.com')
insert into Person (Id, Email) values ('3', 'a@b.com')
Problem Description
Write a SQL query to find all duplicate emails in a table named Person.
For example, your query should return the following for the above table:
Note: All emails are in lowercase.
My Solution (Oracle)
SELECT email
FROM person
GROUP BY email
HAVING COUNT(email) > 1;
간단하게 HAVING 절을 이용했다.
COUNT 함수를 통해 같은 email이 1개 초과인 경우, 해당 이메일을 선택한다.