Your question is SQL for Declining Inventory Turnover. Start with the requirements and the three tables on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Write a SQL query to identify stores with declining inventory turnover over the last 3 months, including month-over-month change and rank by decline severity.
Use the provided store, inventory, and sales data. Include only stores with valid turnover values for all three months and decreases in both month-over-month comparisons.
store_id, store_name, first_month_turnover, latest_month_turnover, first_mom_change, second_mom_change, latest_mom_change, total_decline, and decline_rank.total_decline descending, with lower store_id breaking ties.| Column | Type | Description |
|---|---|---|
| store_idPK | INTEGER | Unique store identifier |
| store_name | VARCHAR(100) | Store display name |
| city | VARCHAR(80) | Store city |
| region | VARCHAR(40) | Operating region |
| Column | Type | Description |
|---|---|---|
| inventory_idPK | INTEGER | Unique monthly inventory record |
| store_id | INTEGER | Referenced store identifier |
| month_start | DATE | First day of the inventory month |
| average_inventory_units | NUMERIC(12,2) | Average inventory units held during the month |
| Column | Type | Description |
|---|---|---|
| sales_idPK | INTEGER | Unique monthly sales record |
| store_id | INTEGER | Referenced store identifier |
| month_start | DATE | First day of the sales month |
| units_sold | INTEGER | Units sold during the month |