Last updated
Evaluate whether each store is maintaining inventory levels in line with monthly product demand.
Evaluate whether each store is maintaining inventory levels in line with monthly product demand.
Your dataset contains three tables from a retail inventory system: 1. An Inventory_Movements table tracking stock added or removed per product per store over time 2. An Orders table with each order placed at a store 3. An Order_Items table with the product and quantity sold in each order
| Column | Type | Key / Notes |
|---|---|---|
| movement_id | INT | PK |
| store_id | INT | |
| product_id | INT | |
| movement_date | DATE | |
| quantity_delta | INT |
| Column | Type | Key / Notes |
|---|---|---|
| order_id | INT | PK |
| store_id | INT | |
| order_date | DATE |
| Column | Type | Key / Notes |
|---|---|---|
| order_item_id | INT | PK |
| order_id | INT | FK |
| product_id | INT | |
| quantity | INT |
Inventory_Movements — 12 rows
| movement_id | store_id | product_id | movement_date | quantity_delta |
|---|---|---|---|---|
| 1 | 1 | 101 | 2024-01-01 | 50 |
| 2 | 1 | 101 | 2024-02-01 | 20 |
| 3 | 1 | 101 | 2024-03-01 | 15 |
| 4 | 1 | 102 | 2024-01-01 | 40 |
| 5 | 1 | 102 | 2024-02-01 | 10 |
| 6 | 1 | 102 | 2024-03-01 | 5 |
| 7 | 2 | 101 | 2024-01-01 | 60 |
| 8 | 2 | 101 | 2024-02-01 | 25 |
| 9 | 2 | 101 | 2024-03-01 | 20 |
| 10 | 2 | 102 | 2024-01-01 | 35 |
| 11 | 2 | 102 | 2024-02-01 | 15 |
| 12 | 2 | 102 | 2024-03-01 | 10 |
Orders — 12 rows
| order_id | store_id | order_date |
|---|---|---|
| 1 | 1 | 2024-01-10 |
| 2 | 1 | 2024-02-12 |
| 3 | 1 | 2024-03-15 |
| 4 | 1 | 2024-01-20 |
| 5 | 1 | 2024-02-22 |
| 6 | 1 | 2024-03-25 |
| 7 | 2 | 2024-01-11 |
| 8 | 2 | 2024-02-13 |
| 9 | 2 | 2024-03-17 |
| 10 | 2 | 2024-01-21 |
| 11 | 2 | 2024-02-23 |
| 12 | 2 | 2024-03-27 |
Order_Items — 12 rows
| order_item_id | order_id | product_id | quantity |
|---|---|---|---|
| 1 | 1 | 101 | 48 |
| 2 | 2 | 101 | 70 |
| 3 | 3 | 101 | 95 |
| 4 | 4 | 102 | 25 |
| 5 | 5 | 102 | 60 |
| 6 | 6 | 102 | 55 |
| 7 | 7 | 101 | 58 |
| 8 | 8 | 101 | 80 |
| 9 | 9 | 101 | 120 |
| 10 | 10 | 102 | 34 |
| 11 | 11 | 102 | 50 |
| 12 | 12 | 102 | 65 |
Write a SQL query that evaluates whether each store maintains inventory levels in line with monthly sales demand. Your query should: 1. Calculate the monthly on-hand (cumulative) inventory for each product at each store 2. Calculate the total monthly sales for each product at each store 3. Compare inventory with sales and classify as: • "Within Demand" — if inventory is within ±5 units of sales • "Inventory Issue" — otherwise Your result table should have: store_id, product_id, mnth_yr, classification.
Your output should look like this (partial example):
| store_id | product_id | mnth_yr | classification |
|---|---|---|---|
| 1 | 101 | January, 2024 | Within Demand |
| 1 | 101 | February, 2024 | Within Demand |
| … | … | … | … |