Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing
Back
  1. Home
  2. Interview prep
  3. What is a running total?

SQL · Window Functions

What is a running total?

Mediumsql-20
running totalcumulative sumwindow

Question

What is a running total?

Solution

A running total is a cumulative sum.

Example:

Day   Sales
1     100
2     200
3     50

Running total:

100
300
350

SQL:

SUM(sales) OVER (
    ORDER BY sale_date
    ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
)

The important part is:

ORDER BY sale_date

because SQL needs to know the sequence.

🎯 Put this concept into practice

Solidify this answer with real hands-on interview drills in the browser studio.

Open related drill →
PreviousNext