Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Analyze Delivery Performance with Subqueries

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

Your question is Analyze Delivery Performance with Subqueries. 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

You are given delivery-level data and courier metadata. Write a PostgreSQL query that returns each courier’s on-time delivery rate and average delivery time for completed deliveries in the last 30 days, but only for couriers who completed at least 5 deliveries. Also include a flag showing whether each courier’s average delivery time is better than the overall average for the same period. Use subqueries to keep the analysis readable.

Schema

couriers
ColumnTypeDescription
courier_idPKINTPrimary key for each courier
courier_nameVARCHAR(100)Courier display name
regionVARCHAR(50)Operating region
deliveries
ColumnTypeDescription
delivery_idPKINTPrimary key for each delivery
courier_idINTForeign key to couriers.courier_id
order_idINTOrder identifier
assigned_atTIMESTAMPWhen the delivery was assigned
delivered_atTIMESTAMPWhen the delivery was completed, if completed
promised_minutesINTPromised delivery time in minutes
actual_minutesINTActual delivery time in minutes
statusVARCHAR(20)Delivery status such as completed, canceled, or returned
Tablescouriersdeliveries
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results