Spent nothing, still on the list
- O(n log n) · Hard
- Full plan
- SQL
- joins
- nulls
- grouping
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
| name | spent |
|---|---|
| Ann | 299.9 |
| Luke | 797.5 |
| Chloë | 119.8 |
| Mason | 52.5 |
| Valerie | 61.25 |
| Dylan | 958.9 |
| Hannah | 0 |
| Brian | 0 |
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.idIt 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.