May 23, 2013 at 6:25 pm
Can anyone please tell me how to calculate the Average Value and select it as a column?
I am trying to add AVG(TotalValue) as AgvSales on the top of query but throws error
Column 'SalesData.SaleDate' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
May 23, 2013 at 9:49 pm
You missed group by, here is one example:
select EmployeeKey,AVG(SalesAmountQuota) as Amout_Avg
from [dbo].[FactSalesQuota]
group by EmployeeKey
May 23, 2013 at 9:49 pm
You missed group by, here is one example:
select EmployeeKey,AVG(SalesAmountQuota) as Amout_Avg
from [dbo].[FactSalesQuota]
[highlight=#ffff11] group by EmployeeKey[/highlight]
May 23, 2013 at 11:39 pm
Any select query with aggerate function requires a GROUP By clause with columns list to be grouped on.
May 24, 2013 at 4:33 pm
Bhaskar.Shetty (5/23/2013)
Any select query with aggerate function requires a GROUP By clause with columns list to be grouped on.
Not quite true. Many of the aggregate functions can be used with the OVER clause. It may not give the answer you want because it operates slightly differently (depends on how the partioning of the OVER clause is setup), but it doesn't require a GROUP BY.
--Jeff Moden
Change is inevitable... Change for the better is not.
May 24, 2013 at 4:35 pm
tswapnars 90250 (5/23/2013)
Can anyone please tell me how to calculate the Average Value and select it as a column?I am trying to add AVG(TotalValue) as AgvSales on the top of query but throws error
Column 'SalesData.SaleDate' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Please post the query. Just adding a GROUP BY to a query where you didn't plan for it can lead to a real world of hurt.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply