Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
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 feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
SQL for On-Time Delivery Rate
00:00
5 left

SQL for On-Time Delivery Rate

MediumSQL · PostgreSQL

Problem

Amazon DSP operations leaders need a daily view of delivery performance by delivery station. Write a PostgreSQL query that joins package delivery records to delivery routes and station information.

Requirements

  1. Analyze delivered packages from 2025-02-10 through 2025-02-11, inclusive.
  2. Return one row per station and route date with delivered package count, on-time delivery rate, and average delay in minutes.
  3. Count a package as on time when delivered_at is less than or equal to promised_at. Early deliveries contribute zero minutes to average delay.
  4. Exclude failed, pending, or undelivered packages, and order results by route date and station code.

Schema

stations
ColumnTypeDescription
station_idPKINTPrimary key for the delivery station
station_codeVARCHAR(10)Amazon DSP station code
station_nameVARCHAR(100)Station display name
delivery_routes
ColumnTypeDescription
route_idPKINTPrimary key for the delivery route
station_idINTReferences stations.station_id
route_dateDATEDate on which the route operated
driver_nameVARCHAR(100)Driver assigned to the route
package_deliveries
ColumnTypeDescription
delivery_idPKINTPrimary key for the package delivery
route_idINTReferences delivery_routes.route_id
promised_atTIMESTAMPPromised delivery timestamp
delivered_atTIMESTAMPActual delivery timestamp
statusVARCHAR(20)Current package delivery status
Tablesstationsdelivery_routespackage_deliveries
Interviewer

Your question is SQL for On-Time Delivery Rate. Start with the requirements and the three 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.