Section: CTEs and window functions

Compute a running total

sql
sql
SELECT created_at,
       amount,
       SUM(amount) OVER (ORDER BY created_at) AS running_total
FROM invoices;
Explanation

Great for revenue charts and time-series analytics.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing CTEs and window functions
Use a CTE to stage a subquery
Name an intermediate result set.
OpenIn sheetsqlsame section
Use a recursive CTE
Walk a hierarchy such as categories or folders.
OpenIn sheetsqlsame section
Assign row numbers
Rank rows within an ordered result.
OpenIn sheetsqlsame section
Rank rows by score
Assign rank values with ties.
OpenIn sheetsqlsame section
Use an INNER JOIN
Return rows that match in both tables.
OpenIn sheetsql1 tag match
Use a LEFT JOIN
Keep parent rows even if the child is missing.
OpenIn sheetsql1 tag match