Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rank Uptime Outliers

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

Your question is Rank Uptime Outliers. 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

Waymo Fleet Operations wants to compare autonomous vehicles by their daily operational uptime. Write a PostgreSQL query that aggregates completed operational intervals, ranks vehicles within each service date, and identifies unusually strong performers.

Requirements

  1. Join vehicles to uptime intervals and calculate total operational minutes per vehicle per service date. Count only intervals with status = 'operational', a non-null end time, and a positive duration.
  2. Use DENSE_RANK() to rank vehicles within each date by total uptime descending.
  3. Return only vehicles in the top two dense-rank positions whose uptime exceeds that day's average vehicle uptime. Include the vehicle identifier, label, date, uptime minutes, daily average, and rank.
  4. Order results by service date, rank, and vehicle identifier.

Schema

vehicles
ColumnTypeDescription
vehicle_idPKINTUnique vehicle identifier
vehicle_labelVARCHAR(30)Fleet-facing vehicle label
modelVARCHAR(30)Waymo vehicle model
vehicle_uptime_events
ColumnTypeDescription
event_idPKINTUnique uptime event identifier
vehicle_idINTVehicle associated with the event
service_dateDATEOperational calendar date
started_atTIMESTAMPInterval start time
ended_atTIMESTAMPInterval end time, null for incomplete intervals
statusVARCHAR(20)Operational event status
Tablesvehiclesvehicle_uptime_events
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results