71. Daily Cumulative Sales (RANGE vs ROWS)
HardWindow FunctionsRANGE frameROWS frameWindow FunctionsFrame ties
When an OVER clause has ORDER BY keys with ties, the frame mode matters:
RANGEframes group all peer rows (rows equal on theORDER BYkey) together — they all share one running value.ROWSframes count physical rows one at a time, so tied rows get different running values depending on physical order.
The daily_sales table has multiple sale rows per sale_date. We want a per-day cumulative total: every row of a given day should show the same running total, namely the sum of all sales on that day and all earlier days. That requires a RANGE frame.
Task: return each sale with its correct per-day cumulative total.
Return columns sale_date, amount, cume_total, ordered by sale_date ascending, then amount 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.