Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Vehicle Mode Duration by Trip

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

Your question is Vehicle Mode Duration by Trip. 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 Waymo Driver state-change logs and trip boundaries. Write a PostgreSQL query to calculate, for each trip, the total time the vehicle spent in autonomous mode versus manual mode. Treat each state row as effective until the next state change within the same trip; for the final state in a trip, use the trip end time. Ignore rows where the state is NULL.

Schema

waymo_trips
ColumnTypeDescription
trip_idPKINTUnique trip identifier
vehicle_idINTVehicle identifier
route_nameVARCHAR(100)Waymo service route or area
trip_start_tsTIMESTAMPTrip start timestamp
trip_end_tsTIMESTAMPTrip end timestamp
waymo_vehicle_state_logs
ColumnTypeDescription
log_idPKINTUnique state log identifier
trip_idINTTrip tied to the state log
event_tsTIMESTAMPTimestamp when the vehicle state changed
vehicle_stateVARCHAR(20)Vehicle mode such as autonomous or manual
Tableswaymo_tripswaymo_vehicle_state_logs
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results