596. Classes More Than 5 Students
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:
For example:
+———+————+
| student | class |
+———+————+
| A | Math |
| B | English |
| C | Math |
| D | Biology |
| E | Math |
| F | Computer |
| G | Math |
| H | Math |
| I | Math |
+———+————+
Should output:
+———+
| class |
+———+
| Math |
+———+
Note:
The students should not be counted duplicate in each course.
解答:输出超过5个学生班级即可,没注意Note里说不可重复计算学生数量,用例里面也确实出现了重复项,加上DISTINCT
就可以了:
- 一般方法:
- 子查询