Skip to the content

Which day do we close?

Problem

The owner is going to close one day a week to rest, and first wants to see how busy the store is each day: how many orders and how many units have landed on a Monday, on a Tuesday, and so on through Sunday.

The '%w' format of STRFTIME gives the day of the week as text from '0' to '6', and '0' is Sunday. Only orders dated up to today, January 15, 2026, count. The one dated the 20th has a mistyped date, and the 20th is a Tuesday: counting it would give the store a Tuesday it never had.

Show three columns, in this order: the name of the day (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday), its orders, and its units. The rows go from Monday to Sunday. A day of the week with no orders doesn't show up.

What it has to return

These rows, in this order

daymadeunits
Monday24
Wednesday11
Thursday23
Friday110
Saturday23
Sunday38

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
  STRFTIME('%w', placed) AS num,
  COUNT(*) AS made,
  SUM(quantity) AS units
FROM orders
GROUP BY STRFTIME('%w', placed)
ORDER BY num;
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 →