AnalystPath

Shifts Above the Warehouse Average

SQLHardSenior level~15 min

Problem

Table `Shifts` records, for each picker, how many orders they handled on a given shift: `shift_id`, `picker_id`, and `orders_picked`. Table `Pickers` maps each `picker_id` to a `full_name` and the `warehouse` they belong to.

A warehouse's average load is the average of `orders_picked` across every shift worked by pickers assigned to that warehouse. Find every shift whose `orders_picked` is strictly greater than the average load of the picker's warehouse.

Return `picker_id`, `shift_id`, `full_name` aliased as `picker_name`, and `orders_picked` aliased as `shift_orders`, ordered by `picker_id` then `shift_id`.

Tables

Example rows — the live problem includes the full dataset.

Shifts
shift_idpicker_idorders_picked
1145
1290
2312
Pickers
picker_idfull_namewarehouse
1MaraNorth
2TomasSouth
3PriyaSouth

Expected output

Your answer should return 2 rows with the columns picker_id, shift_id, picker_name, shift_orders.

Starter code (SQL)

SELECT *
FROM Shifts;

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