Reputation: 151
I would like to calculate the total amount of expenditure and the calculate the average value from the number of rows like this:
SELECT AVG(SUM(expenditure)) from INCOME;
However, there is a error say "misuse of aggregate function sum()"
how can I achieve this?
Upvotes: 1
Views: 5988
Reputation: 300559
You can't calculate the average of the total sum as there is only one total.
The average AVG()
function already calculates the total as part of its logic.
This is what you want:
SELECT AVG(expenditure) as AverageExpenditure,
SUM(expenditure) as TotalExpenditure
from INCOME;
Upvotes: 3
Reputation: 1208
SELECT AVG(expenditure) AS avg_exp, SUM(expenditure) AS sum_exp FROM INCOME;
Upvotes: 2