Leetcode SQL

596. Classes More Than 5 Students

There is a table courses with columns: student and class

Please list out all classes which have more than or equal to 5 students.

For example, the table:

| student | class |
| A | Math |
| B | English |
| C | Math |
| D | Biology |
| E | Math |
| F | Computer |
| G | Math |
| H | Math |
| I | Math |

Should output:

| class |
| Math |

Hint: Use “Having” clause than “Where”. Having is to used to filter grouped or aggregated data.


select class from courses group by class
having count(distinct(student))>=5;





My homepage to record my thought processes for solving SQL and Algorithm questions

Recommended from Medium

SOLID design Principles

Learning development skills with… gaming?

Windows Won’t Boot — What Shall I Do?

How to read an Excel/CSV file in bubble.io using AWS S3/Lambda

Django check username is available or not using ajax

Changing the Encryption Type of All Objects in a S3 Bucket

Docker Networking — Containers Communication

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


In love with telling stories with data

More from Medium

Leetcode SQL 10 Days Study Plan(Day2) With Oracle SQL(Delete, Decode, Case When, Update)

Leetcode SQL

LeetCode SQL| 182. Duplicate Emails

01. One SQL A Day (15/06/22)