Skip to content

Commit 0097a80

Browse files
Added Classes More than 5 students
1 parent 9abfa2e commit 0097a80

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
Classes More Than 5 Students
3+
https://leetcode.com/problems/classes-more-than-5-students/
4+
5+
There is a table courses with columns: student and class
6+
7+
Please list out all classes which have more than or equal to 5 students.
8+
9+
For example, the table:
10+
11+
+---------+------------+
12+
| student | class |
13+
+---------+------------+
14+
| A | Math |
15+
| B | English |
16+
| C | Math |
17+
| D | Biology |
18+
| E | Math |
19+
| F | Computer |
20+
| G | Math |
21+
| H | Math |
22+
| I | Math |
23+
+---------+------------+
24+
Should output:
25+
26+
+---------+
27+
| class |
28+
+---------+
29+
| Math |
30+
+---------+
31+
32+
33+
Note:
34+
The students should not be counted duplicate in each course.
35+
*/
36+
37+
SELECT class
38+
FROM courses
39+
GROUP BY class
40+
HAVING count(DISTINCT(student)) > 4

0 commit comments

Comments
 (0)