New faces
- O(n log n) · Hard
- Full plan
- SQL
- subqueries
- grouping
- joins
Problem
The owner is flipping through the order book with one question in mind: is the store growing, or is it the same people buying every time? The answer is a day-by-day list of how many orders came in and how many customers ordered that day for the first time ever.
Show the date, then that day's orders, then the new faces, with the most recent day on top. A day when only returning customers ordered still gets its line, with a 0. And someone who places two orders on their very first day is one new face.
The order dated the 20th gets a line too, under the date as it was entered. It's Luke's, and Luke had already ordered on the 4th: mistyped or not, it brings in nobody new.
What it has to return
These rows, in this order
| placed | made | new_faces |
|---|---|---|
| 2026-01-20 | 1 | 0 |
| 2026-01-15 | 2 | 1 |
| 2026-01-14 | 1 | 1 |
| 2026-01-12 | 2 | 0 |
| 2026-01-11 | 1 | 0 |
| 2026-01-10 | 1 | 1 |
| 2026-01-09 | 1 | 1 |
| 2026-01-04 | 2 | 1 |
| 2026-01-03 | 1 | 1 |
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 placed, COUNT(*) AS made
FROM orders
GROUP BY placed
ORDER BY placed DESC;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.