문제
Classes More Than 5 Students - LeetCode
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.
풀이
- 각 class 그룹화
- having을 통한 student count
- 끝
코드
select class
from Courses
group by class
having count(student) > 4
링크
LeetCode/0596-classes-more-than-5-students at main · K-MarkLee/LeetCode
LeetCode/0596-classes-more-than-5-students at main · K-MarkLee/LeetCode
Collection of LeetCode questions to ace the coding interview! - Created using [LeetHub](https://github.com/QasimWani/LeetHub) - K-MarkLee/LeetCode
github.com
'Daily 코드카타 > SQL' 카테고리의 다른 글
코딩테스트 SQL 코드카타 (Number of Employees) (1) | 2024.12.09 |
---|---|
코딩테스트 SQL 코드카타 (Followers count) (1) | 2024.12.06 |
코딩테스트 SQL 코드카타 (Percentage of Users) (1) | 2024.11.27 |
코딩테스트 SQL 코드카타 (Project Employees) (0) | 2024.11.26 |
코딩테스트 SQL 코드카타 (Employee Bonus) (1) | 2024.11.20 |