有一個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