I have a database containing records collected every 0.1 seconds, and I need to time-average the data from a given day to once every 20 minutes. So I need to return a day’s worth of data averaged to every 20 minutes which is 24*3 values.
Currently I do a separate AVG call to the database for each 20-minute period within the day, which is 24*3 calls. My connection to the database seems a little slow (it is remote) and it takes ~5 minutes to do all the averages. Would it be faster to do a single query in which I access the entire day’s worth of data then average it to every 20 minutes? If it helps to answer the question, I have to do some arithmetic to the data before averaging, namely multiplying several table columns.
I have a database containing records collected every 0.1 seconds, and I need to
Share
You can calculate the number of minutes since midnight like:
If you divide that by 20, you get the number of the 20 minute interval. For example,
00:10would fall in interval0,00:30in interval1, and15:30in interval46, and so on. With this formula, you can group on 20 minute intervals like:You can do math inside the
avgcall, like: