Skip to the content

Spent nothing, still on the list

Problem

The owner wants a list of every customer and what each one has spent at the store: each product's price times the units ordered, added up. Every order counts, the one dated the 20th included.

Show the customer's name and their total, in that order. Someone who has never ordered anything isn't left out, and isn't left with an empty cell either: they show up with a 0.

What it has to return

These rows, in any order

namespent
Ann299.9
Luke797.5
Chloë119.8
Mason52.5
Valerie61.25
Dylan958.9
Hannah0
Brian0

This is what comes out with the data in the practice database this challenge uses. The column names don’t count, so name yours however you like: what counts is how many there are and the order they come in. Besides this one, the challenge has hidden tests with other data that are revealed when you submit your solution.

You start with this

SQL

SELECT c.name
FROM customers c
LEFT JOIN orders o
  ON o.customer_id = c.id
Solve this challenge

It opens in your browser, with the editor and the tests. This challenge is part of the full plan; the O(1) and O(log n) ones are free.

More O(n log n) challenges

See all challenges →