Interview Question Bank · PERCENTILE_CONT · interval to minutes
5. Median food prep time by restaurant
MediumFood deliveryQuestion #233
Concept: PERCENTILE_CONT · interval to minutesshow
Kitchen times are skewed: one slow ticket drags the average well above a typical wait, so the median is the sturdier figure. PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY x) averages the two middle values when a group has an even count, while PERCENTILE_DISC picks one real value. It returns double precision, so cast to numeric before ROUND(x, 1).
Example (different data):
SELECT branch, ROUND((PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY EXTRACT(EPOCH FROM served_at - ordered_at) / 60))::numeric, 1) AS median_wait FROM coffee_orders GROUP BY branch;
Your task
Brightbowl couriers complain about waiting at the counter. Ops measures food prep as the time from placed_at to picked_up_at and wants a typical figure per restaurant that one bad evening can't distort.
Using delivered orders only, return restaurant (name), pickups (number of delivered orders) and median_prep_minutes (the PERCENTILE_CONT median of minutes from placed_at to picked_up_at, ROUND(...::numeric, 1)). Sort by median_prep_minutes descending, then restaurant.
Starting Postgres in your browser…
Checking your access…