I would like to gather the averages for player-count
for each hour of the day so we can get a general idea of when players are most on. The data is stored in a MySQL data.
My table is as follows:
id | datetime | player-count | players
1 | 2023-11-10 23:10:05 | 32 | [{jsondata}]
1 | 2023-11-10 23:15:02 | 10 | [{jsondata}]
1 | 2023-11-10 23:20:05 | 25 | [{jsondata}]
1 | 2023-11-10 23:25:02 | 9 | [{jsondata}]
1 | 2023-11-10 23:30:01 | 3 | [{jsondata}]
I am unsure of how to construct the MySQL query. I tried something along
SELECT *,AVG(`player-count`) AS average from `".$db->prefix."server_player_count` GROUP BY CAST(`datetime` as DATE), DATEPART(Hour, StartDate) ORDER BY CAST(`datetime` as DATE) ASC;");
But doesn’t seem to work. Anyone point me in the right direction.
2
Answers
How about something like this:
Demo: http://sqlfiddle.com/#!9/99d103/1
It looks very much like what you suggested, so what went wrong? Why did you ask the question?
so here you are not adding rest of the columns in group by condition as you are mentioning * in select statement. so this is throwing error(this is my assumption)
below is the query which will work to get the player_count day and hour wise