Spend per customer

MediumJoinsE-commerce

The problem

Show every customer's name and the total amount of their delivered orders, as total_spent.

Customers with no delivered orders must still appear, with a total_spent of 0.

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: Customers who never ordered →

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 (10 rows)
Expected output
nametotal_spent
Meera Iyer3600
Tara Joshi0
Isha Kapoor4700
Diya Nair4750
Neel Patel0
Kabir Singh300
Rohan Das700
Vikram Rao950
Aarav Mehta2000
Sana Khan0

Row order doesn’t matter 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.