Skip to content

Latest commit

 

History

History
62 lines (44 loc) · 1.29 KB

596-classes-more-than-5-students.md

File metadata and controls

62 lines (44 loc) · 1.29 KB

596. Classes More Than 5 Students - 超过5名学生的课

有一个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:
学生在每个课中不应被重复计算。


题目标签:

题目链接:LeetCode / LeetCode中国

题解

Language Runtime Memory
mysql 1548 ms N/A
# Write your MySQL query statement below
SELECT class
FROM courses
GROUP BY class
HAVING COUNT(DISTINCT student) > 4;