Classes More Than 5 Students - Sql - Easy - LeetCode
💻 coding

Classes More Than 5 Students - Sql - Easy - LeetCode

1 min read 120 words
1 min read
ShareWhatsAppPost on X
  • 1The article discusses a SQL query to find classes with five or more unique students.
  • 2It provides an example table structure and the expected output for the query.
  • 3The SQL statement uses GROUP BY and HAVING clauses to filter the results.

AI-generated summary · May not capture all nuances

Key Insight
AskGif

"The article discusses a SQL query to find classes with five or more unique students."

Classes More Than 5 Students - Sql - Easy - LeetCode

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 | +---------+

Note: The students should not be counted duplicate in each course.

# Write your MySQL query statement below
select class from courses group by class having count(distinct student)>4;

Enjoyed this article?

Share it with someone who'd find it useful.

ShareWhatsAppPost on X

sumitc91

Published on 17 October 2020 · 1 min read · 120 words

Part of AskGif Blog · coding

You might also like

Classes More Than 5 Students - Sql - Easy - LeetCode | AskGif Blog