Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rolling 30-Day Latency SQL

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

Your question is Rolling 30-Day Latency SQL. 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

Write a SQL query to calculate the rolling 30-day average delivery latency across regional hubs, broken down by vendor tier.

Use completed deliveries only, where latency is the elapsed time from shipped_at to delivered_at. Each 30-day period includes the current delivery date and the preceding 29 calendar days.

Output

  1. One row per hub, vendor tier, and delivery date.
  2. Return hub_name, region, vendor_tier, delivery_date, and rolling_30_day_avg_latency_hours.
  3. Include only non-null vendor tiers and completed deliveries. Order by region, hub name, vendor tier, and delivery date ascending.

Schema

regional_hubs
ColumnTypeDescription
hub_idPKINTUnique regional hub identifier
hub_nameVARCHAR(100)Regional hub name
regionVARCHAR(100)Geographic region containing the hub
vendors
ColumnTypeDescription
vendor_idPKINTUnique vendor identifier
vendor_nameVARCHAR(100)Vendor name
tierVARCHAR(30)Vendor service tier
deliveries
ColumnTypeDescription
delivery_idPKINTUnique delivery identifier
hub_idINTRegional hub handling the delivery
vendor_idINTVendor responsible for the delivery
shipped_atTIMESTAMPShipment start timestamp
delivered_atTIMESTAMPDelivery completion timestamp
Tablesregional_hubsvendorsdeliveries
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results