I want to do an average : the problem is for 1 item i'm calculating the AVG of each elements (working) but as soon as i want the GLOBAL average of the averages of the categories (something and foo) it doesn't work (mysql throw me an error : see the syntax i used just below).
I need to do that because i want to sort the result by the global average
SELECT AVG(AVG(category1)+AVG(category2)) /2 as moy
.....
ORDER BY moy DESC
Thanks,
edit : I would like to have the average of averages of each category edit 2 :
got table : server (...) got table : answer_poll (price, interface, services, quality)
a user's got 1 server, and he can answer to a poll for this server severall times
SELECT s.name , s.type , COUNT(s.GSP_nom) as nb_votes,
TRUNCATE(AVG(quality), 2) as quality, TRUNCATE(AVG(price), 2) as price,
TRUNCATE(AVG(interface), 2) 开发者_高级运维 as interface, TRUNCATE(AVG(services), 2) as services
FROM answer_poll AS v
INNER JOIN server AS s ON v.idServ = s.idServ
GROUP BY s.name
ORDER BY global average :d
This request = the average for each category, but i want the average of the averages :p
May be that?:
SELECT AVG(avg_) as superavg
FROM (
SELECT category, AVG(val) as avg_
FROM foo_table
GROUP BY category
) as avgs;
精彩评论