70. Running Maximum Balance
MediumWindow FunctionsMAX OVERRunning AggregateWindow Functions
An aggregate used as a window function — MAX(col) OVER (ORDER BY ...) — computes a running value: at each row it reports the maximum seen so far (the default frame is everything from the start of the partition up to the current row).
The balances table records an account's end-of-day balance, one row per day.
Task: for each day, show the balance and the highest balance reached up to and including that day (the running maximum / high-water mark).
Return columns day, balance, running_max, ordered by day 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.