Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rank Top Vehicle Configurations

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

Your question is Rank Top Vehicle Configurations. 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

Mercedes-Benz Group uses vehicle telemetry to compare configuration performance across development and fleet vehicles. Write a PostgreSQL query to identify the three best-performing configurations during January 2025.

Requirements

  1. Join configurations, vehicles, and telemetry records.
  2. Include telemetry recorded from 2025-01-01 through 2025-01-31, inclusive.
  3. Use CTEs to calculate cumulative distance and energy consumption for each configuration, along with the number of contributing vehicles and telemetry records.
  4. Use RANK() to rank configurations by cumulative distance in descending order, return ranks 1 through 3, and order the final result by rank.
  5. Ignore configurations with fewer than two telemetry records in the period. Treat NULL energy readings as zero when calculating cumulative energy.

Schema

configurations
ColumnTypeDescription
configuration_idPKINTConfiguration identifier
configuration_codeVARCHAR(20)Mercedes-Benz configuration code
model_nameVARCHAR(80)Vehicle model name
powertrainVARCHAR(30)Powertrain type
vehicles
ColumnTypeDescription
vehicle_idPKINTVehicle identifier
configuration_idINTReferenced configuration
vinVARCHAR(17)Vehicle identification number
fleet_statusVARCHAR(20)Current fleet status
telemetry
ColumnTypeDescription
telemetry_idPKINTTelemetry record identifier
vehicle_idINTReferenced vehicle
recorded_atDATEDate of telemetry capture
distance_kmDECIMAL(10,2)Distance measured in kilometers
energy_consumed_kwhDECIMAL(10,2)Energy consumed in kilowatt-hours
Tablesconfigurationsvehiclestelemetry
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results