Daily Net Inventory Movement
Problem
A warehouse logs how many units moved in and out of stock each day.
Table: `Movements`
```text
+-----------+---------+
| Column | Type |
+-----------+---------+
| move_day | date |
| direction | varchar |
| units | int |
+-----------+---------+
(move_day, direction) is the primary key.
direction is either 'inbound' or 'outbound'.
Each row gives the total number of units moved in that direction on that day.
```
For each day, report the net change in stock, defined as inbound units minus outbound units. Name the column `net_change` and order the result by `move_day`.
Tables
Example rows — the live problem includes the full dataset.
| move_day | direction | units |
|---|---|---|
| 2021-09-01 | inbound | 10 |
| 2021-09-01 | outbound | 8 |
| 2021-09-02 | inbound | 15 |
Expected output
Your answer should return 4 rows with the columns move_day, net_change.
Starter code (SQL)
SELECT *
FROM Movements;Solve this SQL question free
Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock