SQL interview question: Running total of daily revenue

medium
SUM OVER
GROUP BY
window frame

Return each order date with that day's revenue and the running total of revenue up to and including that day. One row per date, ordered by date.

Expected columns: order_date, revenue, running_total. Column names don't have to match. Runs on SQLite in your browser.

Tables: customers + orders

CREATE TABLE customers (
  id INTEGER PRIMARY KEY,
  name TEXT NOT NULL,
  signup_date TEXT NOT NULL
);
INSERT INTO customers VALUES
  (1, 'Acme', '2025-12-01'), (2, 'Globex', '2025-12-15'), (3, 'Initech', '2026-01-10'),
  (4, 'Umbrella', '2026-02-01'), (5, 'Hooli', '2026-03-05');

CREATE TABLE orders (
  id INTEGER PRIMARY KEY,
  customer_id INTEGER NOT NULL REFERENCES customers(id),
  order_date TEXT NOT NULL,
  amount REAL NOT NULL
);
INSERT INTO orders VALUES
  (1, 1, '2026-01-05', 120), (2, 2, '2026-01-09', 80), (3, 1, '2026-01-20', 200),
  (4, 3, '2026-02-02', 150), (5, 1, '2026-02-14', 90), (6, 2, '2026-02-14', 60),
  (7, 3, '2026-03-01', 300), (8, 2, '2026-03-18', 75), (9, 1, '2026-03-30', 110),
  (10, 3, '2026-04-04', 220);

Your query

Ctrl/Cmd + Enter

FAQ