All problems

Transcript vs GPA

hardSQLJoinsGroupBy

The stored grade point average on a student's record at Fairhaven University is maintained by a separate nightly job, and the data team has stopped trusting it. Their check is to put the stored figure next to the mean of the marks actually on record for that student and look for rows that disagree — both are on the same 0-4 scale, so they should be close.

Sittings with no mark entered contribute nothing to the computed figure, and a student with no sittings at all has nothing to compare and stays off the report.

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 name, the stored gpa, and the mean of that student's marks rounded to two decimal places as avg_grade. Highest stored gpa first; students sharing a stored figure are separated alphabetically by name.

Example output

Shape only — these students and figures are invented:

name gpa avg_grade
Mira Sun 3.95 3.88
Dana Ruiz 3.7 3.55
Yara Blum 3.45 3.6
Hugo Lam 2.9 3.02
Tomas Vega 2.4 2.15

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

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…