Problem Statement
Which frame returns a classic running total that includes the current row?
Explanation
A running total accumulates from the start of the partition up to the current row. The ROWS frame is precise and counts physical rows, which avoids surprises with duplicate sort values.
RANGE frames can expand to peers that share the same ORDER BY value, which can change results. For financial and inventory totals, prefer ROWS for predictable behavior.
Code Solution
SolutionRead Only
SELECT order_id, sale_date, amount,
SUM(amount) OVER (
PARTITION BY customer_id
ORDER BY sale_date, order_id
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
) AS running_total
FROM sales;