Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top 5 Underperforming Routes

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Top 5 Underperforming Routes. Start with the requirements and the two tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Amazon Prime Now Operations needs to identify delivery routes with the longest average cycle time. Write a PostgreSQL query that ranks the five slowest routes using completed deliveries during January 2025.

Requirements

  1. Calculate cycle time in minutes as the difference between delivered_at and picked_up_at.
  2. Include only rows with status = 'DELIVERED' and timestamps within January 2025.
  3. Include routes with at least one completed delivery, calculate their average cycle time, and return the five highest averages.
  4. Return route ID, route name, average cycle time, and completed delivery count. Sort by average cycle time descending, then route ID ascending.

Schema

prime_now_routes
ColumnTypeDescription
route_idPKINTUnique Prime Now route identifier
route_nameVARCHAR(80)Operational route name
service_zoneVARCHAR(40)Geographic service zone
prime_now_deliveries
ColumnTypeDescription
delivery_idPKINTUnique delivery identifier
route_idINTRoute used for the delivery
picked_up_atTIMESTAMPTimestamp when the order left the station
delivered_atTIMESTAMPTimestamp when the order reached the customer
statusVARCHAR(20)Delivery lifecycle status
Tablesprime_now_routesprime_now_deliveries
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results