Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Optimize Slow Telemetry Queries

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

Your question is Optimize Slow Telemetry Queries. 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

Explain how you would optimize a slow-running SQL query that aggregates millions of daily telemetry data points at May Mobility.

Write a PostgreSQL query that returns the requested daily depot-level telemetry summary for the specified date range. Also explain how you would investigate and improve performance at this scale.

Output

  1. One row per depot and telemetry date with depot_name, telemetry_date, telemetry_points, active_vehicles, total_miles, average_speed_mph, and fault_events.
  2. Include only active vehicles and readings from March 1 through March 2, 2025.
  3. Order by telemetry_date ascending, then depot_name ascending.

Schema

telemetry_readings
ColumnTypeDescription
reading_idPKBIGINTUnique telemetry reading identifier
vehicle_idINTVehicle that produced the reading
reading_atTIMESTAMPTimestamp when the reading was recorded
miles_deltaNUMERIC(8,2)Miles recorded since the previous reading
speed_mphNUMERIC(6,2)Vehicle speed in miles per hour
fault_codeVARCHAR(30)Optional diagnostic fault code
autonomous_vehicles
ColumnTypeDescription
vehicle_idPKINTUnique vehicle identifier
depot_idINTAssigned service depot
is_activeBOOLEANWhether the vehicle is currently active
service_depots
ColumnTypeDescription
depot_idPKINTUnique service depot identifier
depot_nameVARCHAR(80)Display name of the service depot
Tablestelemetry_readingsautonomous_vehiclesservice_depots
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results