DataLane

10. Running total of daily revenue

mediumProNot started~12 minWindow functionsTime series

Asked in screens shaped like: Stripe, Airbnb, Booking

Finance wants a cumulative revenue column beside the daily number so they can see the month build up. Aggregate to a day first, then run the window over that result — not over raw orders.

Requirements

  • Columns: order_day, revenue, running_revenue
  • Only status = 'completed'
  • running_revenue is the cumulative sum of revenue ordered by day
  • Both money columns rounded to 2 decimals, ordered by order_day

Expected output

order_day, revenue, running_revenue

Row order is graded, so ORDER BY matters here.

SQL editor

Loading SQL engine…

Ctrl/Cmd + Enter submits

Run your query to see the result set.

Pro problem

Medium problems unlock with Pro

Easy pads stay free. Medium and hard SQL and Python problems — editor, tests, hints, and solutions — open after you upgrade to Pro or coaching.

See plansPractice free easy problems
↑↓ navigate openesc close