10000 add : 596 · h-j-13/LeetCode-Database@e43348e · GitHub
[go: up one dir, main page]

Skip to content

Commit e43348e

Browse files
committed
add : 596
1 parent 515b85c commit e43348e

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# LeetCode 596. Classes More Than 5 Students
2 10A0E +
## 题目
3+
There is a table ```courses``` with columns: student and class
4+
5+
Please list out all classes which have more than or equal to 5 students.
6+
7+
For example, the table:
8+
9+
+---------+------------+
10+
| student | class |
11+
+---------+------------+
12+
| A | Math |
13+
| B | English |
14+
| C | Math |
15+
| D | Biology |
16+
| E | Math |
17+
| F | Computer |
18+
| G | Math |
19+
| H | Math |
20+
| I | Math |
21+
+---------+------------+
22+
Should output:
23+
24+
+---------+
25+
| class |
26+
+---------+
27+
| Math |
28+
+---------+
29+
Note:
30+
The students should not be counted duplicate in each course.
31+
32+
题目大意,找出选修人数超过5门的学生,每门课的学生不应该重复计算
33+
34+
## 解题思路
35+
36+
使用 group by 分组后 count(distinct 学生) 大于5的即为需要展示的内容
37+
38+
```sql
39+
SELECT class FROM courses GROUP BY class HAVING count(DISTINCT student) >= 5;
40+
```

0 commit comments

Comments
 (0)
0