Report Classes with at Least Five Enrolled Students

Quick Overview

Return each class with at least five students enrolled. The (student,class) key prevents duplicate enrollment rows for the same student in one class. Class ordering is unrestricted.

Report Classes with at Least Five Enrolled Students

Company: Amazon

Role: Software Engineer

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

### Problem Return each class with at least five students enrolled. The (student,class) key prevents duplicate enrollment rows for the same student in one class. Class ordering is unrestricted. ### Tables Table: `Courses` ```text +-------------+---------+ | Column Name | Type | +-------------+---------+ | student | varchar | | class | varchar | +-------------+---------+ (student, class) is the primary key (combination of columns with unique values) for this table. Each row of this table indicates the name of a student and the class in which they are enrolled. ``` ### Example ```text Courses (student,class): (Ada,Art), (Bo,Art), (Cam,Art), (Dee,Art), (Eli,Art), (Fox,Music) Output (class): (Art) ``` ### What a Strong Answer Covers - Count students separately for each class. - Include a class with exactly five enrolled students and return each qualifying class once. ### Follow-up Questions - How would you change the result if duplicate enrollment records were allowed? - How would you include classes with no students in a full enrollment report?

Overview: Return each class with at least five students enrolled. The (student,class) key prevents duplicate enrollment rows for the same student in one class. Class ordering is unrestricted.

Amazon logo
Amazon
Jul 5, 2026
easySoftware EngineerOtherData Manipulation (SQL/Python)
0
0

Problem

Return each class with at least five students enrolled. The (student,class) key prevents duplicate enrollment rows for the same student in one class. Class ordering is unrestricted.

Tables

Table: Courses

+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| student     | varchar |
| class       | varchar |
+-------------+---------+
(student, class) is the primary key (combination of columns with unique values) for this table.
Each row of this table indicates the name of a student and the class in which they are enrolled.

Example

Courses (student,class): (Ada,Art), (Bo,Art), (Cam,Art), (Dee,Art), (Eli,Art), (Fox,Music)
Output (class): (Art)

What a Strong Answer Covers Guidance

  • Count students separately for each class.
  • Include a class with exactly five enrolled students and return each qualifying class once.

Follow-up Questions Guidance

  • How would you change the result if duplicate enrollment records were allowed?
  • How would you include classes with no students in a full enrollment report?