Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Start free
Efficient Telemetry Aggregation Query
00:00
5 left

Efficient Telemetry Aggregation Query

MediumSQL · PostgreSQL

Problem

Caterpillar's fleet monitoring system needs a daily summary of telemetry for active machines operating at North American sites. Write a PostgreSQL query that aggregates readings while preserving active machines that have no telemetry during the reporting period.

Requirements

  1. Include active machines at sites where region = 'North America' for January 1 through January 3, 2026.
  2. Return one row per machine and telemetry date with reading count, average engine temperature, and maximum fuel rate.
  3. Preserve machines without readings using LEFT JOIN, and label each row as NO DATA, UNAVAILABLE, HIGH, ELEVATED, or NORMAL based on the aggregated temperature.
  4. Order the result by machine ID and telemetry date, with machines without readings included at the end of their machine group.

Output details

  • Return columns in this order: machine_id, model, site_name, reading_date, reading_count, avg_engine_temp_c, max_fuel_rate_lph, telemetry_status.
  • Use an inclusive lower bound of 2026-01-01 00:00:00 and an exclusive upper bound of 2026-01-04 00:00:00.
  • Round avg_engine_temp_c to one decimal place and preserve max_fuel_rate_lph numeric precision.
  • Use 0 for missing reading_count, retain NULL for missing averages and maximums, and classify null aggregates as UNAVAILABLE or no telemetry as NO DATA.
  • Sort machine_id ascending, then reading_date ascending with NULL dates last.

Schema

cat_sites
ColumnTypeDescription
site_idPKINTUnique Caterpillar operating or test site identifier
site_nameVARCHAR(120)Name of the operating or test site
regionVARCHAR(40)Geographic region used for reporting
cat_machines
ColumnTypeDescription
machine_idPKINTUnique machine identifier
modelVARCHAR(40)Caterpillar machine model
site_idINTOperating site reference
statusVARCHAR(20)Current machine lifecycle status
telemetry_readings
ColumnTypeDescription
reading_idPKINTUnique telemetry reading identifier
machine_idINTMachine that emitted the reading
reading_atTIMESTAMPTimestamp when the reading was captured
engine_temp_cDECIMAL(6,2)Engine temperature in degrees Celsius
fuel_rate_lphDECIMAL(8,2)Fuel consumption rate in liters per hour
Tablescat_sitescat_machinestelemetry_readings
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the three tables are in the Question tab.

Sign up free to run or submit. Log in
CodePostgreSQL
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 1
Run your query to see results here.