LeetCode 596: Classes with at Least 5 Students
LeetCode 596 Explained: Solutions for Classes with 5 or More Students

I'm Varchasv, a Data Engineer working on enterprise data integration.
Currently on a 90-problem challenge to level up my technical skills and switch to a more development-focused role.
What I'm doing:
- Solving 2 Leetcode problems daily (SQL + DSA).
- Blogging about each problem.
- Building in public.
My Goal - Land a better data engineering role by mid-2026.
Follow my journey !!
Date: January 28, 2026
Category: SQL
Time Taken: minute
Difficulty: Easy
Problem Statement
Write a solution to find all the classes that have at least five students.
Link: Classes With at Least 5 Students
My Approach
Since we need to count the students in each class, we will use GROUP BY on the class. To filter out classes that have at least 5 students, we will include that condition in the HAVING clause.
Solution Code
SELECT class
FROM Courses
GROUP BY class
HAVING COUNT(DISTINCT student) >= 5
Key Takeaway: Nothing, very easy problem.
Pattern: Aggregation
Mistakes I Made: Again I forgot that I can use aggregate functions in the HAVING clause and instead I used a Subquery.
Series: 90 Days of Data Engineering Progress: 24/90 problems completed
Tags: #DEQuest #LeetCode #SQL #DataEngineering #BuildInPublic