Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL Crash Metrics Over 30 Days
00:00
5 left

SQL Crash Metrics Over 30 Days

HardSQL · PostgreSQL

Problem

Write a SQL query to extract and aggregate crash metrics from a highly nested operational vehicle dataset over a rolling 30-day window for AURORA.

Use the latest run date as the window endpoint. Safely handle missing, malformed, or scalar event payloads, and preserve groups whose mileage is NULL.

Output

  1. One row per vehicle class, region, and metric date within the rolling window.
  2. Columns: vehicle_class, region, metric_date, daily_miles, daily_crashes, daily_severe_crashes, rolling_30_day_miles, rolling_30_day_crashes, rolling_30_day_severe_crashes, and crashes_per_100k_miles.
  3. Include NULL regions, order by vehicle class, region with NULLs last, and metric date.

Schema

fleet_vehicles
ColumnTypeDescription
vehicle_idPKINTUnique vehicle identifier
vehicle_classVARCHAR(40)Operational vehicle class
regionVARCHAR(40)Fleet operating region
operational_runs
ColumnTypeDescription
run_idPKINTUnique operational run identifier
vehicle_idINTVehicle used for the run
run_started_atTIMESTAMPRun start timestamp
operational_payloadJSONBNested mileage and event payload
Tablesfleet_vehiclesoperational_runs
Interviewer

Your question is SQL Crash Metrics Over 30 Days. Start with the requirements and the two tables in the Question tab.

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.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.