有一个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 |
+---------+
提示:
学生在每个课中不应被重复计算。
子查询
# Write your MySQL query statement below
SELECT c2.class FROM
( SELECT c1.class,
COUNT( DISTINCT c1.student) AS NUM FROM courses c1
GROUP BY c1.class )
c2 WHERE c2.NUM >= 5;