使用AVG&一起数

时间:2013-11-25 20:11:45

标签: sql count sql-server-2000 average

我需要平均销售额。但是当我尝试执行我的查询时,我得到了这个错误(再次:() 消息130,第15级,状态1,第2行 无法对包含聚合或子查询的表达式执行聚合函数。

以下是我试图运行的内容

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

1 个答案:

答案 0 :(得分:0)

感谢@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