简体   繁体   中英

Calculate Average per Day MYSQL

I am running MYSQL version 4.0.16. My hosting provider manages the server and therefore I cannot upgrade to a later version.

I have been given a task of building a help desk report. It needs to show the total number of calls over an 8 day period per day , the total number of calls closed on the same day and it then needs to show the average number of calls for each of these days over an 30 day period.

For formatting purposes I have had to left join a list of dates. This is purely so my report will not have any missing dates.

I am struggling to figure out how I can calculate the average number of calls per date over a 30 days period. Can anyone help me do this? The average should be calculated per day, so the function needs to count all of the calls over the last 30 days prior to each date and then divide this by 30 to calculate the average.

SELECT COUNT(call_id)/30 
FROM call_table 
WHERE call_date BETWEEN curdate() and adddate(curdate() interval -30 day)

Not tested. I normally use SQL server so the MySQL syntax may be slightly off, but if I am understanding you correctly then it would be similar to this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM