Write a SQL query to find stores with the highest shrink rate by month and compare them to the chain average at Americaneagle.
Use active stores with valid monthly inventory counts. Define the chain average as the weighted shrink rate across included stores, using expected units as the weight.
month, store_name, shrink_rate_pct, chain_average_pct, and difference_from_chain_pct.| Column | Type | Description |
|---|---|---|
| store_idPK | INT | Unique store identifier |
| store_name | VARCHAR(100) | Americaneagle store name |
| region | VARCHAR(50) | Operating region |
| is_active | BOOLEAN | Whether the store is currently active |
| Column | Type | Description |
|---|---|---|
| inventory_idPK | INT | Unique monthly inventory record |
| store_id | INT | Referenced store identifier |
| month_start | DATE | First day of the inventory month |
| expected_units | INT | Units expected according to inventory records |
| counted_units | INT | Units found during the physical count |