Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL for On-Time Delivery Rate

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

Your question is SQL for On-Time Delivery Rate. Start with the requirements and the three 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 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
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results