MySQL:AVG的AVG不可能吗? [英] MySQL : AVG of AVG impossible?

查看:90
本文介绍了MySQL:AVG的AVG不可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做一个平均值:问题是我正在计算每个元素的AVG(有效),但是一旦我想要该类别平均值的GLOBAL平均值(某些东西和foo)它不起作用(mysql向我抛出一个错误:请参见下面使用的语法).

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

谢谢

edit:我希望获得每个类别的平均值的平均值

edit : I would like to have the average of averages of each category edit 2 :

获取表:服务器(...) 得到表:answer_poll(价格,接口,服务,质量)

got table : server (...) got table : answer_poll (price, interface, services, quality)

用户有1台服务器,他可以多次回答该服务器的民意调查

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

此请求=每个类别的平均值,但我想要平均值的平均值:p

This request = the average for each category, but i want the average of the averages :p

推荐答案

可能是吗?:

SELECT AVG(avg_) as superavg
FROM (
    SELECT category, AVG(val) as avg_
    FROM foo_table
    GROUP BY category
) as avgs;

这篇关于MySQL:AVG的AVG不可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆