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