Code RoomWarehouse average unit cost
HardPrep Room Coding #5129

Warehouse average unit cost

SQLAlgorithms & data structuresSenior~13 min

For each warehouse, return `city` and `avg_unit_cents`: the total stock value divided by the total quantity, rounded to a whole number. A warehouse holding zero units returns NULL rather than failing. Order by city.

What a strong answer looks like

Say what the query is meant to return before you write it, and name the shape of the answer: how many rows, grouped by what. Then watch the NULLs and the duplicates, because that is where most of these are lost.

Run onlyA query runs as one statement, so there is nothing to step through. Run it and read the rows.

0:00 of about 13 min

Expected, in this order

cityavg_unit_cents
Memphis966
Osaka19900
Rotterdam8362

Your result

Run your query to compare.

1 more set of rows are waiting. Free with an account.