14. Month-over-Month Change
MediumWindow FunctionsLAG()previous-row access
LAG() reaches back to a previous row within the ordered window.
Task: for each month return month, revenue, and delta — the change in
revenue versus the previous month (revenue - previous revenue). The first
month has no predecessor, so its delta is NULL. Order by month.
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.