This is a standard SQL problem where you are given a Courses table with columns student and class. You need to find all the classes that have at least five students enrolled.
Microsoft and Google use this "Easy" database question to test your understanding of basic SQL filtering after aggregation. It evaluations your ability to use the GROUP BY clause combined with the HAVING clause. This is a day-to-day task for anyone working with relational databases.
The pattern is SQL Aggregation with Post-filtering.
class column.COUNT().HAVING clause to filter out groups where the count is less than 5.Table Courses:
| student | class |
|---|---|
| A | Math |
| B | Math |
| C | Math |
| D | Math |
| E | Math |
| F | Science |
class: Math has 5 students, Science has 1.count >= 5.
Result: Math.The most common mistake is trying to use a WHERE clause for the count (e.g., WHERE COUNT(student) >= 5). In SQL, WHERE filters rows before they are grouped, while HAVING filters the results after they are grouped. Another mistake is forgetting that COUNT(*) or COUNT(student) is needed within the HAVING clause.
Remember the order of operations in SQL: FROM -> WHERE -> GROUP BY -> HAVING -> SELECT -> ORDER BY. Knowing that HAVING is the correct place for aggregate filters is a fundamental SQL concept.