Given a table of manufacturing machine logs, write a query to calculate the rolling average of machine temperature over a three-hour window.
Use the timestamp for each reading and calculate the window separately for each machine. Include readings exactly three hours before the current reading, ignore NULL temperatures in the average, and round the result to two decimal places.
machine_id, logged_at, temperature_celsius, and rolling_avg_temperature.machine_id, logged_at, and log_id.| Column | Type | Description |
|---|---|---|
| log_idPK | BIGINT | Unique identifier for the machine log |
| machine_id | VARCHAR(20) | Manufacturing machine identifier |
| logged_at | TIMESTAMP | Timestamp when the temperature was recorded |
| temperature_celsius | NUMERIC(6,2) | Machine temperature in degrees Celsius |