Skip to content

Commit 8740e54

Browse files
committed
Add solution 182 [sql]
group by
1 parent dc32115 commit 8740e54

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Complete [solutions](https://github.com/doocs/leetcode/tree/master/solution) to
3737
| 175 | [Combine Two Tables](https://github.com/doocs/leetcode/tree/master/solution/175.Combine%20Two%20Tables) | `SQL` |
3838
| 176 | [Second Highest Salary](https://github.com/doocs/leetcode/tree/master/solution/176.Second%20Highest%20Salary) | `SQL` |
3939
| 181 | [Employees Earning More Than Their Managers](https://github.com/doocs/leetcode/tree/master/solution/181.Employees%20Earning%20More%20Than%20Their%20Managers) | `SQL` |
40+
| 182 | [Duplicate Emails](https://github.com/doocs/leetcode/tree/master/solution/182.Duplicate%20Emails) | `SQL` |
4041
| 189 | [Rotate Array](https://github.com/doocs/leetcode/tree/master/solution/189.Rotate%20Array) | `Array` |
4142
| 198 | [House Robber](https://github.com/doocs/leetcode/tree/master/solution/198.House%20Robber) | `Dynamic Programming` |
4243
| 203 | [Remove Linked List Elements](https://github.com/doocs/leetcode/tree/master/solution/203.Remove%20Linked%20List%20Elements) | `Linked List` |
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
## 查找重复的电子邮箱
2+
### 题目描述
3+
4+
编写一个 SQL 查询,查找 `Person` 表中所有重复的电子邮箱。
5+
6+
示例:
7+
```
8+
+----+---------+
9+
| Id | Email |
10+
+----+---------+
11+
12+
13+
14+
+----+---------+
15+
```
16+
17+
根据以上输入,你的查询应返回以下结果:
18+
```
19+
+---------+
20+
| Email |
21+
+---------+
22+
23+
+---------+
24+
```
25+
26+
**说明:**所有电子邮箱都是小写字母。
27+
28+
### 解法
29+
`Email` 进行分组,选出数量大于 1 的 `Email` 即可。
30+
31+
```sql
32+
# Write your MySQL query statement below
33+
select Email
34+
from Person
35+
group by Email
36+
having count(Email) > 1;
37+
```
38+
39+
#### Input
40+
```json
41+
{"headers": {"Person": ["Id", "Email"]}, "rows": {"Person": [[1, "[email protected]"], [2, "[email protected]"], [3, "[email protected]"]]}}
42+
```
43+
44+
#### Output
45+
```json
46+
{"headers":["Email"],"values":[["[email protected]"]]}
47+
```

0 commit comments

Comments
 (0)