Skip to the content

The notebook by the register

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

placedhow_manymoney
2026-01-201320
2026-01-152179.7
2026-01-141899
2026-01-12235.65
2026-01-111378
2026-01-10145.5
2026-01-09152.5
2026-01-042288.5
2026-01-03191

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.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) challenges

See all challenges →