How do you calculate a running total?
Model answer
SUM(amount) OVER (ORDER BY order_date ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW). Specify the frame explicitly, because the default frame with ORDER BY treats rows with equal order values as peers, which can surprise you.
Learn this topic
Window Functions: ROW_NUMBER, RANK and Running Totals in the course SQL for Beginners: Learn Databases Step by Step.
Sign in to add your own answer.