views:

82

answers:

1

Hi,

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

+2  A: 

May be that?:

SELECT AVG(avg_) as superavg
FROM (
    SELECT category, AVG(val) as avg_
    FROM foo_table
    GROUP BY category
) as avgs;
newtover
i'll try that ASAP and i'll let you know
Tristan
+1: Correct - you can not use an aggregate on another, you have to reference the column from a derived table/inline view/subselect.
OMG Ponies
thanks, it works ;)
Tristan