What went out today
- O(n²) · Very hard
- Full plan
- SQL
- changing data
- subqueries
- nulls
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
| id | name | stock |
|---|---|---|
| 1 | Keyboard | 12 |
| 2 | Mouse | 30 |
| 3 | Monitor | 5 |
| 4 | Cable | 0 |
| 5 | Laptop | 3 |
| 6 | Tablet | 7 |
| 7 | Headphones | 12 |
| 8 | Speaker | 0 |
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'
);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
- Which day do we close?SQL · dates · grouping · conditionals
- You started with a KeyboardSQL · window functions · joins
- A line for every daySQL · recursion · dates · window functions
- Arriving WednesdaySQL · dates · conditionals
- Best day yetSQL · window functions · grouping · subqueries
- First with lastSQL · window functions · joins · grouping