The notebook by the register
- O(n) · Medium
- Full plan
- SQL
- grouping
- joins
Problem
The owner writes down in a notebook what gets ordered each day, and is tired of adding it up by hand. For each day that had orders, show three columns, in this order: the date, how many orders came in, and how much money they add up to (each product's price times the units ordered, rounded to 2 decimals).
The most recent day goes on top, and the order dated the 20th counts like the rest. A day with no orders doesn't show up: no row in orders mentions it.
What it has to return
These rows, in this order
| placed | how_many | money |
|---|---|---|
| 2026-01-20 | 1 | 320 |
| 2026-01-15 | 2 | 179.7 |
| 2026-01-14 | 1 | 899 |
| 2026-01-12 | 2 | 35.65 |
| 2026-01-11 | 1 | 378 |
| 2026-01-10 | 1 | 45.5 |
| 2026-01-09 | 1 | 52.5 |
| 2026-01-04 | 2 | 288.5 |
| 2026-01-03 | 1 | 91 |
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 o.placed, p.price
FROM orders o
JOIN products p
ON o.product_id = p.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.
More O(n) challenges
- What the team makesSQL · grouping · joins · decimals
- Where are the books from?SQL · grouping · joins · sorting
- Where do our orders come from?SQL · grouping · joins · nulls
- Where there's more than oneSQL · grouping · nulls
- Who owes grades?SQL · grouping · joins · nulls
- A two-credit 10SQL · grouping · joins · decimals