easyGROUP BYHAVING
Classes With At Least 5 Students
Find classes with five or more students enrolled.
Start practicePrompt
Classes With At Least 5 Students
Prompt
Given the courses table below (one row per student enrollment), write a query that returns the class of every class with at least five students.
- Output a single column:
class. - The order of the result does not matter.
- Each row is one enrollment; count rows per class.
Example
| student | class |
|---|---|
| A | Math |
| B | Math |
| C | Math |
| D | Math |
| E | Math |
| F | English |
Expected result:
| class |
|---|
| Math |
Constraints
- There is no primary key; a student may have duplicate rows for the same class.
Tips
GROUP BY classthenHAVING COUNT(*) >= 5.
Expected concepts
- GROUP BY
- HAVING
- COUNT
Schema
CREATE TABLE courses (
student TEXT NOT NULL,
class TEXT NOT NULL
);
Sample data
INSERT INTO courses (student, class) VALUES
('A', 'Math'),
('B', 'Math'),
('C', 'Math'),
('D', 'Math'),
('E', 'Math'),
('F', 'Math'),
('A', 'English'),
('B', 'English'),
('C', 'English'),
('D', 'English');
Additional hidden fixtures are applied during validation to test edge cases.