Introduction
ROWS
RANGE
Default window frame
20. Default window frame - with ORDER BY
Revision

Instruction

Alright! When there is no ORDER BY clause in OVER(...), the query simply treats all rows as the window frame for each row. Nothing shocking, really – that's the kind of queries we wrote in previous parts.

Now, we said the following: if there is an ORDER BY clause, RANGE UNBOUNDED PRECEDING will be used as the default window frame. Let's find out if it's true.

Exercise

Just as in one of the previous exercises, we'll be looking for the running sum of single orders. For each order, show its id, placed date, total_price and the sum of all total prices. Sort the orders by the placed date, but do not specify any window frame.

The sum of total_prices should be calculated as if you wrote RANGE UNBOUNDED PRECEDING.

Stuck? Here's a hint!

Use SUM(total_price) OVER(ORDER BY placed).

Console

Code editor

Result

TableConsole