File tree Expand file tree Collapse file tree
0596-classes-with-at-least-5-students Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 >  ; </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  ; result format is in the following example.</p >
21+
22+ <p >  ; </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 >
Original file line number Diff line number Diff line change 1+ # Write your MySQL query statement below
2+ SELECT class
3+ FROM Courses
4+ GROUP BY class
5+ HAVING COUNT (student) >= 5 ;
You can’t perform that action at this time.
0 commit comments