leetcode182-Duplicate Emails(중복된 데이터 찾기)

1343 단어
문제 설명:
Write a SQL query to find all duplicate emails in a table named Person.
+----+---------+
| 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] | +---------+

문제 해결:
1、distinct
select distinct p1.email from Person p1, Person p2
where p1.email = p2.email and p1.Id != p2.Id

2、group by & having
select email from Person group by email having count(*)>1

좋은 웹페이지 즐겨찾기