Skip to content
We areTOP 1%

Classes With at Least 5 Students

EasyLeetCodeSQL: Aggregation & GROUP BY
Solve on LeetCode(opens in a new tab)
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews
Hint and exampleShow

Group the rows by category and keep only the groups whose row count reaches the threshold, using HAVING.

Example: clubs(student, club) — clubs with at least 2 members

student | club
Asha    | Music
Ravi    | Music
Kiran   | Chess
Meera   | Music
SELECT club
FROM clubs
GROUP BY club
HAVING COUNT(*) >= 2;   -- returns Music (3 members)

More in SQL: Aggregation & GROUP BY

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account