Skip to content
>_sqlbuddy
easyGROUP BYHAVING

Classes With At Least 5 Students

Find classes with five or more students enrolled.

Start practice

Prompt

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

studentclass
AMath
BMath
CMath
DMath
EMath
FEnglish

Expected result:

class
Math

Constraints

  • There is no primary key; a student may have duplicate rows for the same class.

Tips

  • GROUP BY class then HAVING 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.