SQL Server AVGfunction怪异
我在SQL Server AVG计算中看到一些奇怪的行为。
在手动计算,你得到49.277588
但是SQL Server报告的平均值是50.9914
如下所示。
问题:有人可以解释这种差别,为什么发生这种情况?
您可以使用以下查询在AdventureWorks2008数据库上尝试查询
select C.ProductCategoryID, P.ProductSubcategoryID, AVG(P.ListPrice) as 'Average', MIN(P.ListPrice) as 'Miniumum', MAX(P.ListPrice) as 'Maximum' from Production.Product P join Production.ProductSubcategory S on S.ProductSubcategoryID = P.ProductSubcategoryID join Production.ProductCategory C on C.ProductCategoryID = S.ProductCategoryID where P.ListPrice <> 0 group by C.ProductCategoryID, P.ProductSubcategoryID with rollup
[更新]答案
这是Excel中加权平均计算的结果
看起来你在Excel中的平均水平,这是不好的math。
http://wiki.answers.com/Q/Is_an_average_of_averages_accurate