Classes More Than 5 Students Problem


Description

LeetCode Problem 596.

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
+---------+------------+
| student | class      |
+---------+------------+
| A       | Math       |
| B       | English    |
| C       | Math       |
| D       | Biology    |
| E       | Math       |
| F       | Computer   |
| G       | Math       |
| H       | Math       |
| I       | Math       |
+---------+------------+

Should output:

1
2
3
4
5
+---------+
| class   |
+---------+
| Math    |
+---------+


MySQL Solution

1
2
3
4
select class
from courses
group by class
having count(distinct student) >= 5




Related Posts

Investments In 2016 Problem

LeetCode 585. Write a query to print the sum of...

Count Student Number In Departments Problem

LeetCode 580. A university uses 2 data tables, student and...

Classes More Than 5 Students Problem

LeetCode 596. Please list out all classes which have more...

Find Customer Referee Problem

LeetCode 584. Given a table customer holding customers information and...

Customer Placing The Largest Number Of Orders Problem

LeetCode 586. Query the customer_number from the orders table for...

Big Countries Problem

LeetCode 595. Write a SQL solution to output big countries’...