Classes More Than 5 Students Problem
Description
LeetCode Problem 596.
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:
1
2
3
4
5
6
7
8
9
10
11
12
13
+---------+------------+
| student | class |
+---------+------------+
| A | Math |
| B | English |
| C | Math |
| D | Biology |
| E | Math |
| F | Computer |
| G | Math |
| H | Math |
| I | Math |
+---------+------------+
Should output:
1
2
3
4
5
+---------+
| class |
+---------+
| Math |
+---------+
MySQL Solution
1
2
3
4
select class
from courses
group by class
having count(distinct student) >= 5
LeetCode Database - Easy
LeetCode 175
LeetCode 176
LeetCode 181
LeetCode 182
LeetCode 183
LeetCode 196
LeetCode 197
LeetCode 511
LeetCode 512
LeetCode 577
LeetCode 584
LeetCode 586
LeetCode 595
LeetCode 596
LeetCode 597
LeetCode 603
LeetCode 607
LeetCode 610
LeetCode 613
LeetCode 619
LeetCode 620
LeetCode 627
More LeetCode Database
MySQL Tutorials