running total: A cumulative sum computed with a window frame — SUM(...) OVER with rows from the start up to the current row. A running total adds up values row by row, so each row shows the sum so far. Daily revenue with a cumulative month-to-date figure next to it is a typical example.
In SQL you calculate it with a window function: SUM(amount) OVER (ORDER BY day ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW). Add PARTITION BY to restart the total per month or per customer.
What should you keep in mind with running total?
Before window functions, this needed slow self-joins or a loop in application code. Now one query handles it efficiently. Specify ROWS explicitly; the default frame, RANGE, treats rows with the same value in the ordering column as one group, which gives surprising totals when several rows share a date. MySQL 8, PostgreSQL and SQLite all support this.
What does an example of running total look like?
SELECT day, amount, SUM(amount) OVER (ORDER BY day ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS running FROM ledger;