Skip to the content

What went out today

Problem

At closing time, the warehouse subtracts from each product's stock whatever was ordered that day. Today, January 15, 2026, the orders got entered but nobody touched the stock.

Write the change that brings it up to date: each product loses the units of all its orders dated today, whether that's one order or several. Anything nobody ordered today stays as it is. The order dated the 20th isn't included: until someone fixes that date, it isn't one of today's. It's graded by looking at the stock of every product. You can write today as '2026-01-15' or as DATE('now').

What it has to return

After your code, this query runs

SELECT id, name, stock FROM products;

These rows, in any order

idnamestock
1Keyboard12
2Mouse30
3Monitor5
4Cable0
5Laptop3
6Tablet7
7Headphones12
8Speaker0

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

UPDATE products
SET stock = stock - 1
WHERE id IN (
  SELECT product_id
  FROM orders
  WHERE placed = '2026-01-15'
);
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 →