I have a database that keeps a temperature readouts, which are being added - let's say - every minute:
+----+---------------------+-------------+-----------+
| id | timestamp | temperature | sensor_id |
+----+---------------------+-------------+-----------+
| 1 | 2021-12-14 10:10:00 | 68.2 | 1 |
| 2 | 2021-12-14 10:11:00 | 69.0 | 1 |
| 3 | 2021-12-14 10:12:00 | 68.2 | 1 |
+----+---------------------+-------------+-----------+
What will be the most efficient way to get the temperature for hourly / daily / weekly temperature line charts?
For example if I want to display a temperature chart for a day, I want to put 24 points on the chart:
If we are saying about hourly chart I assume it would be acceptable to calculate an average on the fly when getting the data, but what about monthly chart?
What comes to my mind is to keep the average values in separate tables for days/weeks/months and calculate those using some scheduled job. Or is there some other way to acheive that?