Skip to the content

Best day yet

Problem

"Best day we've ever had," the owner says after closing up on a good one, and wants to know how many times that has actually been true. A day sets a record when its money (each product's price times the units ordered) beats the money of every single day before it. The first day with orders counts: it had nothing to beat. Tying the record isn't breaking it.

Show two columns, the day and then its money, rounded to 2 decimals, with the record that still stands on top and the oldest one at the bottom. Orders dated up to today, January 15, 2026, count. The one dated the 20th stays out: a day that hasn't come yet doesn't beat anything.

What it has to return

These rows, in this order

set_onmoney
2026-01-14899
2026-01-11378
2026-01-04288.5
2026-01-0391

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 AS day,
  SUM(p.price * o.quantity)
    AS money
FROM orders o
JOIN products p
  ON o.product_id = p.id
GROUP BY o.placed;
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 →