Interview Questions/SQL/Classes With at Least 5 Students

Classes With at Least 5 Students

Preview mode. Log in to edit, run, submit, and save progress.

Medium

Classes With at Least 5 Students

You are given a Courses table that records which students are enrolled in which classes. Write a SQL query to find all classes that have at least 5 students enrolled. Return the result in any order.

Examples

Example 1

Math has 6 students - qualifies. English has 1, Biology has 1, Computer has 1 - none qualify. Only Math is returned.

Approach hint

Start with a simple approach, explain the trade-off, then move toward a cleaner or more scalable solution.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

query.sql