Use GROUP BY on class
and find the COUNT of students in each class
.
Use the HAVING clause since the WHERE
clause doesn't support aggregate functions
If the table was designed properly without duplicate entries, the following code would work:
SELECT class FROM courses
GROUP BY class
HAVING COUNT(class) >= 5
However, the duplicate entries in the table prevent the above code from working properly.
We use DISTINCT
to remove the duplicate entries.
SELECT class FROM courses
GROUP BY class
HAVING COUNT(DISTINCT student) >= 5