AnalystPath

Warehouses Stocking Heavy Items Too Thinly

SQLMediumMid level~15 min

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.

warehouses
warehouse_idwarehouse_nameregion
1North HubRiverside
2East DepotGlenford
3West YardAshbury
stock
stock_idwarehouse_iditem_nameunitsweight_kg
11Anvil480
21Bracket405
31Clamp2012

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

Related SQL questions