Course Load Check
Academic advising at Fairhaven University keeps an eye on how much each student has taken on. Too heavy a load and the marks slide; too light and a student quietly falls behind on credits and finds out in their final year. The advisors want a workload sheet: each student and how many sittings they have on record across every term.
A sitting counts as work whether or not a mark has come back for it yet — the teaching happened either way. A student with nothing on record has no workload to review and is not on the sheet.
enrollments — one row per sitting: one student taking one course in one term. student_id points at a row in students and course_id at a row in courses. grade is the mark for that sitting, on the same 0-4 scale, and is NULL when no mark has been entered yet. semester is the term the sitting belongs to.
| student_id | course_id | grade | semester |
|---|---|---|---|
| 1 | 1 | 3.7 | Fall2023 |
| 1 | 2 | 3.9 | Spring2024 |
| 2 | 1 | 3.2 | Fall2023 |
| 2 | 3 | 3.5 | Fall2023 |
| 3 | 2 | 4.0 | Spring2024 |
| 3 | 4 | 3.8 | Spring2024 |
| 4 | 3 | 2.9 | Fall2023 |
| 5 | 1 | 3.6 | Fall2023 |
| 5 | 2 | NULL | Spring2024 |
students — one row per enrolled student. gpa is the grade point average already on file for that student, on a 0-4 scale.
| id | name | major | gpa |
|---|---|---|---|
| 1 | Nora Fischer | Computer Science | 3.8 |
| 2 | Omar Haddad | Statistics | 3.4 |
| 3 | Petra Novakova | Computer Science | 3.9 |
| 4 | Quinn Walsh | Mathematics | 3.1 |
| 5 | Ravi Shah | Statistics | 3.6 |
Both tables already exist in the database — there is nothing to create or load.
Task: Write a query that returns one row per student who has at least one sitting on record, with their name and how many sittings they have as courses_taken. Heaviest load first; if two students have the same number, the one whose name comes first alphabetically goes above the other.
Example output
Shape only — these students and counts are invented:
| name | courses_taken |
|---|---|
| Dana Ruiz | 5 |
| Hugo Lam | 5 |
| Mira Sun | 4 |
| Yara Blum | 4 |
| Tomas Vega | 1 |
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in