Classes More Than 5 Students
Task: Write a solution to find all the classes that have at least five students.
Table: Courses
| Column Name | Type |
|---|---|
| student | varchar(255) |
| class | varchar(255) |
Input: Courses table:
| student | class |
|---|---|
| A | Math |
| B | English |
| C | Math |
| D | Biology |
| E | Math |
| F | Computer |
| G | Math |
| H | Math |
| I | Math |
Output:
| class |
|---|
| Math |
View Reference Solution & Explanation ▼
This solution uses the `GROUP BY` clause to aggregate results and a `HAVING` clause to filter the aggregated groups.
SELECT class FROM Courses GROUP BY class HAVING COUNT(student) >= 5;