inblog logo
|
stupefyee
    SQL문제풀기

    [SQL 문제 풀이] Classes With at Least 5 Students (최소 5명 이상의 학생이 있는 수업)

    Stupefyee's avatar
    Stupefyee
    Jun 09, 2025
    [SQL 문제 풀이] Classes With at Least 5 Students (최소 5명 이상의 학생이 있는 수업)
    Contents
    내가 작성한 쿼리
    Classes With at Least 5 Students - LeetCode
    Can you solve this real interview question? Classes With at Least 5 Students - Table: Courses +-------------+---------+ | Column Name | Type | +-------------+---------+ | student | varchar | | class | varchar | +-------------+---------+ (student, class) is the primary key (combination of columns with unique values) for this table. Each row of this table indicates the name of a student and the class in which they are enrolled.   Write a solution to find all the classes that have at least five students. Return the result table in any order. The result format is in the following example.   Example 1: Input: Courses table: +---------+----------+ | student | class | +---------+----------+ | A | Math | | B | English | | C | Math | | D | Biology | | E | Math | | F | Computer | | G | Math | | H | Math | | I | Math | +---------+----------+ Output: +---------+ | class | +---------+ | Math | +---------+ Explanation: - Math has 6 students, so we include it. - English has 1 student, so we do not include it. - Biology has 1 student, so we do not include it. - Computer has 1 student, so we do not include it.
    Classes With at Least 5 Students - LeetCode
    https://leetcode.com/problems/classes-with-at-least-5-students/description/
    Classes With at Least 5 Students - LeetCode
    notion image
    최소 다섯 명의 학생이 있는 모든 수업을 찾기 위한 해결책을 작성하세요. 결과 테이블을 순서에 상관없이 반환하세요.
     

    내가 작성한 쿼리

    MySQL, Oracle

    SELECT class FROM Courses GROUP BY class HAVING COUNT(*) > 4;
    Share article
    Contents
    내가 작성한 쿼리

    stupefyee

    RSS·Powered by Inblog