Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Average Vehicle Idle Time by Zone

MediumSQL · PostgreSQL00:00
I
Practice interviewer
Your interviewer
In session
I
Interviewer

Welcome to the SQL screen.

The question is on your right: Average Vehicle Idle Time by Zone. Read through the requirements and the two tables first.

Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?

You need to log in / sign up to run or submit.

Problem

You are given Waymo ride activity and Waymo Driver vehicle status logs. Write a SQL query to find the average idle time in minutes per vehicle for vehicles operating in a specific geographic zone, using 'Downtown' as the target zone.

Treat a vehicle as idle when its status is 'idle'. Only count idle status records that fall between a ride's end time and the next ride's start time for the same vehicle. Return one row per vehicle in the target zone, along with its average idle time, ordered from highest to lowest average idle time.

Schema

ride_logs
ColumnTypeDescription
ride_idPKINTUnique ride identifier
vehicle_idINTVehicle identifier
zone_nameVARCHAR(50)Geographic zone where the ride occurred
ride_start_tsTIMESTAMPRide start timestamp
ride_end_tsTIMESTAMPRide end timestamp
vehicle_statuses
ColumnTypeDescription
status_idPKINTUnique vehicle status event identifier
vehicle_idINTVehicle identifier
statusVARCHAR(20)Vehicle status at the event timestamp
status_tsTIMESTAMPTimestamp of the status event
Tablesride_logsvehicle_statuses
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results