AnalystPath

Daily Net Inventory Movement

SQLMediumMid level~15 min

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.

Movements
move_daydirectionunits
2021-09-01inbound10
2021-09-01outbound8
2021-09-02inbound15

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

Related SQL questions