The following table receives a dataset (nearly) every minute via cronjob:
id | timestamp | humanTime | userCount
-----------------------------------------------------
1 1482310202 2016-12-21 09:50:07 120
2 1482310262 2016-12-21 09:51:07 126
3 1482310322 2016-12-21 09:52:06 110
4 1482310381 2016-12-21 09:54:06 131
5 ...
Since the cronjob is a query via network, it is not ensured that there are 60 entries in every hour due to possible timeouts.
I would like to calculate the hourly average of the column userCount for the last X hours.
Does anyone have an idea?
P.S.: If there's no way to do this via sql, i'd like to solve this problem via PHP
You just need to extract the date and hour from time. I'd stick with the human time:
If you want the last "n" hours, then include: