我想计算支出总额并从这样的行数计算平均值:
SELECT AVG(SUM(expenditure)) from INCOME;
但是,有一个错误说“滥用聚合函数 sum()”
我怎样才能做到这一点?
您无法计算总和的平均值,因为只有一个总数。
作为其逻辑的一部分, averageAVG()
函数已经计算了总数。
这就是你想要的:
SELECT AVG(expenditure) as AverageExpenditure,
SUM(expenditure) as TotalExpenditure
from INCOME;
SELECT AVG(expenditure) AS avg_exp, SUM(expenditure) AS sum_exp FROM INCOME;