8000 Create LeetCode 182. Duplicate Emails · priyesh0453/SQL-LeetCode@6a0c1a6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6a0c1a6

Browse files
committed
Create LeetCode 182. Duplicate Emails
1 parent 5aed8b4 commit 6a0c1a6

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

Easy/182. Duplicate Emails.sql

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
Table: Person
3+
4+
+-------------+---------+
5+
| Column Name | Type |
6+
+-------------+---------+
7+
| id | int |
8+
| email | varchar |
9+
+-------------+---------+
10+
id is the primary key column for this table.
11+
Each row of this table contains an email. The emails will not contain uppercase letters.
12+
13+
14+
Required Query:
15+
16+
Report all the duplicate emails. Note that it's guaranteed that the email field is not NULL.
17+
18+
19+
SQL Schema:
20+
21+
Create table If Not Exists Person (id int, email varchar(255))
22+
Truncate table Person
23+
insert into Person (id, email) values ('1', 'a@b.com')
24+
insert into Person (id, email) values ('2', 'c@d.com')
25+
insert into Person (id, email) values ('3', 'a@b.com')
26+
27+
28+
Example:
29+
30+
Input:
31+
Person table:
32+
+----+---------+
33+
| id | email |
34+
+----+---------+
35+
| 1 | a@b.com |
36+
| 2 | c@d.com |
37+
| 3 | a@b.com |
38+
+----+---------+
39+
Output:
40+
+---------+
41+
| Email |
42+
+---------+
43+
| a@b.com |
44+
+---------+
45+
*/
46+
47+
-- Solution:
48+
SELECT email
49+
FROM Person
50+
GROUP BY email
51+
HAVING COUNT(email) > 1

0 commit comments

Comments
 (0)
0