Classes With at Least 5 Students
Preview mode. Log in to edit, run, submit, and save progress.
Medium
Description
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.
Database Schema
Courses
| Column Name | Example Value |
|---|---|
| student | A |
| class | Math |
Example
Courses
| student | class |
|---|---|
| A | Math |
| B | English |
| C | Math |
| D | Biology |
| E | Math |
| F | Computer |
| G | Math |
| H | Math |
| I | Math |
Output
| class |
|---|
| Math |
Explanation:
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.
SQL Editor
Loading...
Courses
| student | class |
|---|---|
| A | Math |
| B | English |
| C | Math |
| D | Biology |
| E | Math |
| F | Computer |
| G | Math |
| H | Math |
| I | Math |
Output
| class |
|---|
| Math |