Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL: 90th Percentile by Metro

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

Your question is SQL: 90th Percentile by Metro. 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

Instacart Operations needs to compare delivery performance across metros. Write a PostgreSQL query that calculates the 90th percentile delivery duration for each metro area.

Requirements

  1. Calculate duration in minutes as the difference between delivered_at and pickup_at.
  2. Exclude records with missing timestamps or negative durations.
  3. Join deliveries to metro_areas and return one row per metro with at least one valid delivery.
  4. Use PostgreSQL's continuous percentile function and sort the output alphabetically by metro name.

Schema

order_deliveries
ColumnTypeDescription
delivery_idPKINTEGERUnique delivery identifier
metro_idINTEGERReferences metro_areas.metro_id
pickup_atTIMESTAMPTZShopper pickup timestamp
delivered_atTIMESTAMPTZCustomer delivery timestamp
metro_areas
ColumnTypeDescription
metro_idPKINTEGERUnique metro identifier
metro_nameVARCHAR(100)Instacart metro name
Tablesorder_deliveriesmetro_areas
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results