There is a table courses with columns: student and class
Please list out all classes which have more than or equal to 5 students.
For example, the table:
+---------+------------+
| student | class |
+---------+------------+
| A | Math |
| B | English |
| C | Math |
| D | Biology |
| E | Math |
| F | Computer |
| G | Math |
| H | Math |
| I | Math |
+---------+------------+
Should output:
+---------+
| class |
+---------+
| Math |
+---------+
找出被选5个学生以上选的课程
这里要注意的是,可能同一个学生会多次选同一门课程
所以对课程分组后要对学生进行去重
我也是第一回知道在count()这样的聚合函数里可以使用distinct关键字去重,这样就非常方便了
select class from courses group by class having count(distinct student) >= 5