Question

I am needing to take a average amount of sales. But when I try to execute my query I get this error (again :( ) Msg 130, Level 15, State 1, Line 2 Cannot perform an aggregate function on an expression containing an aggregate or a subquery.

Here is what I am attempting to run

Select SalesMan,
COUNT(CASE WHEN SalesMan IN ('Richard', 'Jose', 'Mendez') AND supCheck IS NOT NULL AND ordered IS      NOT NULL THEN AVG(price1+price2+price3+price4+price5) ELSE NULL END)
FROM PixieStick.dbo.SalesInfo
GROUP BY SalesMan
ORDER BY SalesMan ASC
Was it helpful?

Solution

Thanks to @T I

Select SalesMan,
AVG(CASE WHEN SalesMan IN ('Richard', 'Jose', 'Mendez') AND supCheck IS NOT NULL AND ordered IS        NOT NULL THEN price1+price2+price3+price4+price5 ELSE NULL END)
FROM PixieStick.dbo.SalesInfo
GROUP BY SalesMan
ORDER BY SalesMan ASC
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top