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
- Include active machines at sites where
region = 'North America' for January 1 through January 3, 2026.
- Return one row per machine and telemetry date with reading count, average engine temperature, and maximum fuel rate.
- Preserve machines without readings using
LEFT JOIN, and label each row as NO DATA, UNAVAILABLE, HIGH, ELEVATED, or NORMAL based on the aggregated temperature.
- 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.