Warehouses Stocking Heavy Items Too Thinly
Problem
Each warehouse holds several items, recording the on-hand units and the weight of each item. Find warehouses with a stocking skew: the heaviest item has fewer on-hand units than the lightest item. Only consider warehouses carrying at least three distinct items. Report the skew as the lightest item's units divided by the heaviest item's units, rounded to two decimals. Sort by skew descending, then by warehouse name alphabetically.
Tables
Example rows — the live problem includes the full dataset.
| warehouse_id | warehouse_name | region |
|---|---|---|
| 1 | North Hub | Riverside |
| 2 | East Depot | Glenford |
| 3 | West Yard | Ashbury |
| stock_id | warehouse_id | item_name | units | weight_kg |
|---|---|---|---|---|
| 1 | 1 | Anvil | 4 | 80 |
| 2 | 1 | Bracket | 40 | 5 |
| 3 | 1 | Clamp | 20 | 12 |
Expected output
Your answer should return 3 rows with the columns warehouse_name, stock_skew.
Starter code (SQL)
SELECT *
FROM warehouses;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