Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rolling Average for Telemetry

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

Your question is Rolling Average for Telemetry. 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

Volkswagen Group Italia wants to monitor vehicle operating conditions from telemetry collected across its connected-vehicle fleet. Write a PostgreSQL query that calculates a time-based 30-day rolling average for each vehicle's battery temperature readings.

Requirements

  1. Join telemetry_readings to vehicles and include the vehicle model in the output.
  2. Return only battery_temperature readings, including rows where the reading value is NULL.
  3. Calculate the average for the current reading and all readings for the same vehicle recorded during the preceding 30 days, using a window function ordered by recorded_at.
  4. Return results ordered by vehicle ID and recording timestamp. Round the rolling average to two decimal places.

Schema

vehicles
ColumnTypeDescription
vehicle_idPKINTEGERUnique vehicle identifier
modelVARCHAR(80)Volkswagen vehicle model
marketVARCHAR(40)Sales market
telemetry_readings
ColumnTypeDescription
reading_idPKINTEGERUnique telemetry reading identifier
vehicle_idINTEGERReferenced vehicle identifier
metric_nameVARCHAR(50)Telemetry metric name
reading_valueNUMERIC(8,2)Measured metric value
recorded_atTIMESTAMPTime when the reading was captured
Tablesvehiclestelemetry_readings
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results