题干:
有一个courses 表 ,有: student (学生) 和 class (课程)。
请列出所有超过或等于5名学生的课。
例如,表:
student | class |
---|---|
A | Math |
B | English |
C | Math |
D | Biology |
E | Math |
F | Computer |
G | Math |
H | Math |
I | Math |
A | Math |
应该输出:
class |
---|
Math |
Note:
学生在每个课中不应被重复计算。
分析:
- 这里每个学生不应该被重复计算,所以要用distinct student ,本来的题目的表里面没有最后一项,我自己加进去,是为了提醒,这个distinct student的重要性
- 为了根据科目类型进行统计,我们可以用group by进行分类,并用having count()进行数量的统计
解题:(226ms)