Skip to the content

New faces

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

placedmadenew_faces
2026-01-2010
2026-01-1521
2026-01-1411
2026-01-1220
2026-01-1110
2026-01-1011
2026-01-0911
2026-01-0421
2026-01-0311

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;
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 →