Running total per customer

HardWindow functionsE-commerce

The problem

For delivered orders only, show customer_id, order_id, amount and a running_total of that customer's delivered amounts so far.

The running total restarts for each customer and follows order_date (then order_id). Sort the output by customer_id, order_date, order_id.

Tables · Online shop

Click a table or column name to insert it into your query.

  • INTEGER · primary key
  • TEXT
  • TEXT · can be NULL
  • DATE
Sample rows (10 total)
Sample rows from customers
customer_idnamecitysignup_date
1Aarav MehtaMumbai2025-01-10
2Diya NairBengaluru2025-01-18
3Kabir SinghDelhi2025-02-02
4Meera IyerChennai2025-02-14
5Rohan DasKolkata2025-03-01

  • INTEGER · primary key
  • INTEGER · → customers
  • DATE
  • TEXT · delivered | cancelled | returned | pending
  • INTEGER · rupees
Sample rows (20 total)
Sample rows from orders
order_idcustomer_idorder_datestatusamount
112025-05-01delivered1200
212025-05-15delivered800
312025-06-02cancelled500
422025-05-03delivered2500
522025-05-20delivered450

Next: Month-over-month growth →

Ctrl/⌘ + Enter runs the query. Table and column names are suggested as you type. Press Esc then Tab to leave the editor with the keyboard.

Expected output (14 rows)
Expected output
customer_idorder_idamountrunning_total
1112001200
128002000
2425002500
254502950
2618004750
38300300
41015001500
41115003000
4126003600
514700700
61532003200
6164003600
61711004700
719950950

Row order matters for this question. Numbers are compared with a tiny tolerance; text must match exactly.

Stuck?

Stored on this device only. Your latest query and “solved” status are remembered in this browser only. They don’t sync between devices, and clearing your browser data removes them.