SQL Server AVG功能奇数
-
21-09-2019 - |
题
我在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中的平均水平是不好的数学。
http://wiki.answers.com/q/is_an_average_of_averages_accurate
不隶属于 StackOverflow