A window frame can calculate cumulative values across ordered rows.
A window frame can calculate cumulative values across ordered rows. Read the query line by line and identify the input table, the transformation, and the shape of the result before running it.
SELECT order_id, order_date, amount, SUM(amount) OVER (ORDER BY order_date) AS running_revenue FROM orders ORDER BY order_date;
Before running the example, predict the output columns and whether the query returns one row, many rows, or possibly no rows.
In your own words, explain the main SQL feature in today’s lesson and why it answers the question.
Recall prompt: SUM(amount) OVER (ORDER BY order_date) creates a running total. Close this page section mentally and explain the query from memory before proceeding.
Show each order and cumulative revenue in date order.
SUM(amount) OVER (ORDER BY order_date) creates a running total.