简体   繁体   English

多个平均值的平均值

[英]Average of multiple averages

I'm running a sql query where I have some averages, now I'd like to have the average of those averages so 我正在运行一个sql查询,我有一些平均值,现在我想得到那些平均值的平均值

AVG(q1) as q1,
AVG(q2) as q2,
AVG(q3) as q3,
AVG(q4) as q4,

and then I don't know how to get the average of all averages as I can't do AVG(q1,q2,q3,q4) and AVG(q1+q2+q3+q4+q5) won't return me the total average across all rows and columns, but only the average of each row. 然后我不知道如何得到所有平均值的平均值因为我不能做AVG(q1,q2,q3,q4)AVG(q1+q2+q3+q4+q5)不会让我回归所有行和列的总平均值,但仅为每行的平均值。

最简单的方法是手动计算

(AVG(q1) + AVG(q2) ... + AVG(qn))/(n*1.0)

Yeah you can 'reuse' the values with another SELECT 是的,你可以用另一个SELECT“重用”这些值

SELECT a.*,(q1+q2+q3+q4)/n as avg_all FROM (
  SELECT AVG(q1) as q1,
         AVG(q2) as q2,
         AVG(q3) as q3,
         AVG(q4) as q4.... ) a

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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