Loading the editor…
Count students enrolled in each course.
The registrar is comparing section sizes. A course with no students should still appear with a count of zero if one exists. In this term every course has at least one enrollment, but the query should not assume that.
Return course_name and students. Count enrollment rows per course. Sort by students descending, then course name.
| id | name | program | enrolled_on |
|---|---|---|---|
| 1 | Amina Diallo | Computer Science | 2024-09-01 |
| 2 | Hugo Berger | Computer Science | 2023-09-01 |
| 3 | Sara Iqbal | Economics | 2024-09-01 |
| id | name | program |
|---|---|---|
| 1 | Databases | Computer Science |
| 2 | Algorithms | Computer Science |
| 3 | Microeconomics | Economics |
| id | student_id | course_id | grade |
|---|---|---|---|
| 1 | 1 | 1 | A |
| 2 | 1 | 2 | B |
| 3 | 2 | 1 | A |
Ctrl or Cmd + Enter runs the query. The database resets on every run.
Run the query to see rows from the sample database.
Next exercise: Active shipments per warehouse
Related: Computer science students, Employees and departments