1. Description
Table: Courses
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| student | varchar |
| class | varchar |
+-------------+---------+
(student, class) is the primary key column for this table.
Each row of this table indicates the name of a student and the class in which they are enrolled.
Write an SQL query to report all the classes that have at least five students.
Return the result table in any order.
The query result format is in the following example.
2. Algorithms
GROUP BY clause can aggregate records by distinct value of input column. While we aggregate record, we can extract specific rows using HAVING cluase.
3. Codes
# Write your MySQL query statement below
SELECT class
FROM Courses
GROUP BY class
HAVING COUNT(*) >= 5;
4. Conclusion
'LeetCode > Easy' 카테고리의 다른 글
599 Minimum Index Sum of Two Lists (0) | 2022.09.08 |
---|---|
589 Range Addition II (0) | 2022.09.08 |
595 Big Countries (0) | 2022.09.08 |
594 Longest Harmonious Subsequence (0) | 2022.09.07 |
590 N-ary Tree Postorder Traversal (0) | 2022.09.07 |