Skip to the content

The week of the 4th

Problem

The store closes its books by the week, Sunday through Saturday, and in the notebook by the register each week goes by its Sunday: the one that runs from January 4 to 10 is "the week of the 4th," whether anything came in that Sunday or not. The owner wants the page with every week that had orders.

Show three columns: the date of each week's Sunday, how many orders the week had, and its money (each product's price times the units ordered, rounded to 2 decimals). The most recent week goes on top.

The '%w' format of STRFTIME gives the day of the week as text from '0' to '6', and '0' is Sunday. And the '-1 days' that DATE takes is text like any other: you can also glue it together with ||.

Orders dated up to today, January 15, 2026, count. The one dated the 20th would land in a week that hasn't started yet, and it stays out.

What it has to return

These rows, in this order

sundaymademoney
2026-01-1161492.35
2026-01-044386.5
2025-12-28191

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,
  STRFTIME('%w', placed) AS num,
  DATE(placed, '-1 days')
    AS day_before
FROM orders;
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 →