Write a SQL query to analyze Bed Bath & Beyond store performance by week, joining sales and inventory tables to identify locations with declining sales and low stock.
Use a low-stock threshold of fewer than 20 units. A location is declining when its sales are lower than the immediately preceding week.
store_id, week_start, weekly_sales, previous_week_sales, and inventory_units.week_start ascending, then store_id ascending.| Column | Type | Description |
|---|---|---|
| sale_idPK | INT | Unique sales transaction identifier |
| store_id | INT | Bed Bath & Beyond store identifier |
| sale_date | DATE | Date of the sales transaction |
| sales_amount | DECIMAL(12,2) | Transaction sales amount |
| Column | Type | Description |
|---|---|---|
| inventory_idPK | INT | Unique inventory snapshot identifier |
| store_id | INT | Bed Bath & Beyond store identifier |
| inventory_date | DATE | Date of the inventory snapshot |
| inventory_units | INT | Units available in inventory |