LeetCode 数据库查询题【Easy】:182. Duplicate Emails

链接:https://leetcode.com/problems/duplicate-emails/

Question

Table: Person

1
2
3
4
5
6
7
8
+-------------+---------+
| 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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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.

My Answer

1
2
3
4
select email
from Person
group by email
having count(email) > 1

My Answer’s Performance

6