29. Difference From Subject Average
MediumWindow FunctionsAVG() OVER PARTITION BYrow vs group comparison
Compare each row to the average of its group while keeping every row visible.
Task: for each score return student, subject, score, and diff —
how far the score is from the average score in that subject (score - subject average). Round diff to 2 decimals. Order by subject, then student.
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.