Skip to content

Commit a12b8e3

Browse files
committed
Sync LeetCode submission - Classes With at Least 5 Students - Runtime - 303 ms (64.73%), Memory - 0.0B (100.00%)
1 parent 47054c1 commit a12b8e3

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<p>Table: <code>Courses</code></p>
2+
3+
<pre>
4+
+-------------+---------+
5+
| Column Name | Type |
6+
+-------------+---------+
7+
| student | varchar |
8+
| class | varchar |
9+
+-------------+---------+
10+
(student, class) is the primary key (combination of columns with unique values) for this table.
11+
Each row of this table indicates the name of a student and the class in which they are enrolled.
12+
</pre>
13+
14+
<p>&nbsp;</p>
15+
16+
<p>Write a solution to find all the classes that have <strong>at least five students</strong>.</p>
17+
18+
<p>Return the result table in <strong>any order</strong>.</p>
19+
20+
<p>The&nbsp;result format is in the following example.</p>
21+
22+
<p>&nbsp;</p>
23+
<p><strong class="example">Example 1:</strong></p>
24+
25+
<pre>
26+
<strong>Input:</strong>
27+
Courses table:
28+
+---------+----------+
29+
| student | class |
30+
+---------+----------+
31+
| A | Math |
32+
| B | English |
33+
| C | Math |
34+
| D | Biology |
35+
| E | Math |
36+
| F | Computer |
37+
| G | Math |
38+
| H | Math |
39+
| I | Math |
40+
+---------+----------+
41+
<strong>Output:</strong>
42+
+---------+
43+
| class |
44+
+---------+
45+
| Math |
46+
+---------+
47+
<strong>Explanation:</strong>
48+
- Math has 6 students, so we include it.
49+
- English has 1 student, so we do not include it.
50+
- Biology has 1 student, so we do not include it.
51+
- Computer has 1 student, so we do not include it.
52+
</pre>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Write your MySQL query statement below
2+
SELECT class
3+
FROM Courses
4+
GROUP BY class
5+
HAVING COUNT(student) >= 5;

0 commit comments

Comments
 (0)