Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rolling Battery Temperature by Machine

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

Your question is Rolling Battery Temperature by Machine. Start with the requirements and the one table 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

You are given Tesla battery manufacturing telemetry and asked to write a PostgreSQL query that returns the rolling average of cell_temperature_c over the prior 5 minutes for each machine_id. The rolling window should be time-based, not row-count-based, and must be partitioned by machine so readings from different machines never mix. Return one row per reading with the machine, timestamp, raw temperature, and rolling average, ordered by machine_id and reading_time.

Schema

battery_cell_readings
ColumnTypeDescription
reading_idPKINTUnique identifier for each telemetry reading
machine_idVARCHAR(20)Battery production machine identifier
reading_timeTIMESTAMPTimestamp of the temperature reading
cell_temperature_cNUMERIC(5,2)Measured battery cell temperature in Celsius
sensor_statusVARCHAR(20)Sensor health state such as OK, CALIBRATING, or OFFLINE
Tablesbattery_cell_readings
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results