File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ -- 596. Classes More Than 5 Students
2
+ -- SQL Schema
3
+ -- There is a table courses with columns: student and class
4
+ --
5
+ -- Please list out all classes which have more than or equal to 5 students.
6
+ --
7
+ -- For example, the table:
8
+ --
9
+ -- +---------+------------+
10
+ -- | student | class |
11
+ -- +---------+------------+
12
+ -- | A | Math |
13
+ -- | B | English |
14
+ -- | C | Math |
15
+ -- | D | Biology |
16
+ -- | E | Math |
17
+ -- | F | Computer |
18
+ -- | G | Math |
19
+ -- | H | Math |
20
+ -- | I | Math |
21
+ -- +---------+------------+
22
+ -- Should output:
23
+ --
24
+ -- +---------+
25
+ -- | class |
26
+ -- +---------+
27
+ -- | Math |
28
+ -- +---------+
29
+ --
30
+ --
31
+ -- Note:
32
+ -- The students should not be counted duplicate in each course.
33
+
1
34
select class from courses
2
35
group by class
3
36
having count (distinct student) >= 5 ;
You can’t perform that action at this time.
0 commit comments