Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Top 5 Underperforming Routes
00:00
5 left

Top 5 Underperforming Routes

MediumSQL · PostgreSQL

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
Interviewer

Your question is Top 5 Underperforming Routes. Start with the requirements and the two tables in the Question tab.

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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.