21. Large Classes

A school wants to identify popular classes that have at least 5 students enrolled. This helps the administration in allocating resources, such as assigning larger classrooms or more teaching assistants.

You are given a Courses table with two columns:

╔═════════════╦══════════╗
ā•‘ Column name ā•‘   Type   ā•‘
╠═════════════╬══════════╣
ā•‘   student   ā•‘ varchar  ā•‘
║─────────────┼──────────║
ā•‘    class    ā•‘ varchar  ā•‘
ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•©ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•
  • student: The name of a student.
  • class: The name of the class the student is enrolled in.

Each (student, class) pair is unique. Write an SQL query to find the names of classes where the number of enrolled students is at least 5. Return the result ordered by class in ascending order.

Example 1:

Example:

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 enrolled.
  • English, Biology, and Computer each have only 1 student.

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Hints

0
Ā 
Test Case

Input:

Courses