Skip to main content
πŸ—„οΈ SQL Projects

Running Totals

What you're building

A running (cumulative) total of revenue by order date β€” essential for trend charts and financial reports.

Requirements

Return, for each order (by order_date):

  • order_date
  • daily_revenue β€” revenue on that date (SUM(price * quantity) per date)
  • running_total β€” cumulative revenue up to and including that date

Use a window function:

SUM(daily_revenue) OVER (ORDER BY order_date) AS running_total

Order the final output by order_date ascending.

Tables: orders(id, customer_id, product_id, quantity, order_date) Β· products(id, price)

Stretch goals

  • Add a 7-day rolling average using ROWS BETWEEN 6 PRECEDING AND CURRENT ROW.
  • Partition by month to restart the running total each month.

What this proves

Window functions separate junior from mid-level SQL skills. A running total is the first window function every analyst learns.

⚑ 60 XP
query.sqlRuns in your browser (SQLite/WASM)
Loading editor…
Tests1 to pass
Daily revenue with cumulative running total

Run your code to check these.