Skip to content

Commit f1e9a61

Browse files
committed
Add solution 596 [sql]
1 parent bf3696b commit f1e9a61

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Complete [solutions](https://github.com/doocs/leetcode/tree/master/solution) to
4343
| 344 | [Reverse String](https://github.com/doocs/leetcode/tree/master/solution/344.Reverse%20String) | `Two Pointers`, `String` |
4444
| 581 | [Shortest Unsorted Continuous Subarray](https://github.com/doocs/leetcode/tree/master/solution/581.Shortest%20Unsorted%20Continuous%20Subarray) | `Array` |
4545
| 595 | [Big Countries](https://github.com/doocs/leetcode/tree/master/solution/595.Big%20Countries) | `SQL` |
46+
| 596 | [Classes More Than 5 Students](https://github.com/doocs/leetcode/tree/master/solution/596.Classes%20More%20Than%205%20Students) | `SQL` |
4647
| 605 | [Can Place Flowers](https://github.com/doocs/leetcode/tree/master/solution/605.Can%20Place%20Flowers) | `Array` |
4748
| 695 | [Max Area of Island](https://github.com/doocs/leetcode/tree/master/solution/695.Max%20Area%20of%20Island) | `Array`, `Depth-first Search` |
4849
| 703 | [Kth Largest Element in a Stream](https://github.com/doocs/leetcode/tree/master/solution/703.Kth%20Largest%20Element%20in%20a%20Stream) | `Heap` |
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
## 超过5名学生的课
2+
### 题目描述
3+
4+
有一个 `courses` 表 ,有: **student(学生)****class(课程)**
5+
6+
请列出所有超过或等于5名学生的课。
7+
8+
例如,表:
9+
```
10+
+---------+------------+
11+
| student | class |
12+
+---------+------------+
13+
| A | Math |
14+
| B | English |
15+
| C | Math |
16+
| D | Biology |
17+
| E | Math |
18+
| F | Computer |
19+
| G | Math |
20+
| H | Math |
21+
| I | Math |
22+
+---------+------------+
23+
```
24+
25+
应该输出:
26+
```
27+
+---------+
28+
| class |
29+
+---------+
30+
| Math |
31+
+---------+
32+
```
33+
34+
**Note:**
35+
学生在每个课中不应被重复计算。
36+
37+
### 解法
38+
注意学生可能被重复计算,需要 `distinct`
39+
40+
```sql
41+
# Write your MySQL query statement below
42+
select class from courses group by class having count(distinct student) >= 5
43+
44+
```

0 commit comments

Comments
 (0)