Skip to content

Commit dec0341

Browse files
committed
leetcode sql
1 parent 22d729b commit dec0341

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
https://leetcode.com/problems/duplicate-emails/
3+
4+
Table: Person
5+
6+
+-------------+---------+
7+
| Column Name | Type |
8+
+-------------+---------+
9+
| id | int |
10+
| email | varchar |
11+
+-------------+---------+
12+
id is the primary key column for this table.
13+
Each row of this table contains an email. The emails will not contain uppercase letters.
14+
15+
16+
Write an SQL query to report all the duplicate emails.
17+
18+
Return the result table in any order.
19+
20+
The query result format is in the following example.
21+
22+
Example 1:
23+
24+
Input:
25+
Person table:
26+
+----+---------+
27+
| id | email |
28+
+----+---------+
29+
| 1 | a@b.com |
30+
| 2 | c@d.com |
31+
| 3 | a@b.com |
32+
+----+---------+
33+
Output:
34+
+---------+
35+
| Email |
36+
+---------+
37+
| a@b.com |
38+
+---------+
39+
Explanation: a@b.com is repeated two times.
40+
*/
41+
42+
select email
43+
from person
44+
group by email
45+
having count(email) > 1;
46+
47+
/*
48+
input: {"headers": {"Person": ["id", "email"]},
49+
"rows": {"Person": [[1, "a@b.com"], [2, "c@d.com"], [3, "a@b.com"]]}}
50+
51+
output:
52+
{"headers": ["email"], "values": [["a@b.com"]]}
53+
*/

0 commit comments

Comments
 (0)