有一个courses 表 ,有: student (学生) 和 class (课程)。
请列出所有超过或等于5名学生的课。
例如,表:
student | class |
---|---|
A | Math |
B | English |
C | Math |
D | Biology |
E | Math |
F | Computer |
G | Math |
H | Math |
I | Math |
应该输出:
class |
---|
Math |
Note:
学生在每个课中不应被重复计算。
解答
1SELECT
2 class
3FROM (
4 SELECT
5 class,
6 count(DISTINCT student) as amount
7 FROM courses
8 GROUP BY class
9) t
10WHERE amount >= 5
原题
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/classes-more-than-5-students