Who's Taking More Than One Course?
Academic advising at Fairhaven University is preparing for check-in week. Students carrying more than one course need a longer appointment, so the advisors want that list separated out before the diary is filled.
The registry keeps one row for every student-course pairing rather than a course list per student, which is the right way to store it and the wrong shape for this question. Nothing in the table says how many courses anybody is taking; that number only appears once rows belonging to the same student are considered together.
enrollments — one row per student-course pairing. grade is the final mark, or NULL if the course has not been marked yet; a row exists whether or not a grade does.
| 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 |
The table already exists in the database — there is nothing to create or load.
Task: Write a query returning a single column, student_id, holding every student with more than one enrollment row. An enrollment counts whether or not it has a grade yet, so the ungraded Spring2024 row still counts towards its student. A student with exactly one enrollment does not appear. Hand the ids back smallest first.
Example output — shape only, on invented ids.
| student_id |
|---|
| 4 |
| 6 |
| 8 |
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