본문 바로가기

Algorithm/SQL

(SQL) - LeetCode (easy) 596. Classes More Than 5 Students

반응형

https://leetcode.com/problems/classes-more-than-5-students/description/

 

Classes More Than 5 Students - LeetCode

Can you solve this real interview question? Classes More Than 5 Students - Table: Courses +-------------+---------+ | Column Name | Type | +-------------+---------+ | student | varchar | | class | varchar | +-------------+---------+ (student, class) is the

leetcode.com

group by ~ having 절을 사용해본 문제였습니다.

📕 풀이방법

📔 풀이과정

class열에 대해 goup by를 한 뒤 count를해 나온 학생 수가 5이상인 class들을 courses table로 부터 select해줍니다.


📕 Code

📔 MySQL & Oracle

-- MySQL & Oracle
select class
from courses
group by class
having count(*) >= 5

*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.