51. Weighted Course GPA
HardAggregationweighted averageSUMROUNDGROUP BY
A weighted average weights each value by an importance factor: weighted_avg = SUM(weight * value) / SUM(weight). A plain AVG is wrong here because it would treat a 1-credit and a 4-credit course equally.
Task: for each student, compute their credit-weighted GPA across courses, weighting each course grade_point by its credits.
Return columns student, gpa where gpa = ROUND(SUM(credits * grade_point) / SUM(credits), 2) (round to 2 decimals). Order by gpa descending, then student ascending.
Tables
Loading schema…
Expected outputrows must come back in this order
Computing expected output…
This is the result for the example data above. On Submit your query is graded against this example plus 4 hidden edge cases — 5test cases in all. A sloppy query that only fits the example won't pass.
SQL· SQLite · runs in your browser
⌘/Ctrl+↵ run · ⇧⌘/Ctrl+↵ submit
Run a query to see its output here.