Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Clean Vehicle Delivery Timeline Records

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

Your question is Clean Vehicle Delivery Timeline Records. 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

You are given raw vehicle delivery timeline data with duplicate status events and missing milestone dates. Write a PostgreSQL query that returns one row per delivery for Lucid Air and Lucid Gravity vehicles, keeping only the latest record for each (delivery_id, event_type) pair, then summarizing the cleaned timeline. Your output should include the vehicle model, delivery center, order date, confirmed delivery date, the number of distinct event types captured, and a delivery status flag that marks a record as incomplete_timeline when either the order date or confirmed delivery date is missing.

Use the delivery center table so the result includes center names even if some deliveries have no matching cleaned event rows.

Schema

deliveries
ColumnTypeDescription
delivery_idPKINTUnique delivery record
vehicle_vinVARCHAR(20)Vehicle VIN
vehicle_modelVARCHAR(30)Vehicle model
delivery_center_idINTReference to delivery center
delivery_events
ColumnTypeDescription
event_idPKINTUnique raw event row
delivery_idINTReference to delivery
event_typeVARCHAR(30)Timeline milestone type
event_timestampTIMESTAMPTimestamp recorded for the milestone
delivery_centers
ColumnTypeDescription
delivery_center_idPKINTDelivery center ID
center_nameVARCHAR(50)Delivery center name
Tablesdeliveriesdelivery_eventsdelivery_centers
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results