2009-09-07 7 views
0

Je vois un comportement étrange dans SQL Server AVG calcuation.SQL Server AVG fonction bizarrement

Le calcul manuel, vous obtenez 49.277588
mais SQL Server signale que la moyenne est 50.9914
comme indiqué ci-dessous.

Question: Quelqu'un peut-il expliquer la différence et pourquoi cela se passe?

Vous pouvez essayer la requête sur la base de données AdventureWorks2008 avec requête suivante

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 

alt text

[Mise à jour] Réponse
Voici le résultat du calcul de la moyenne pondérée dans Excel alt text

Répondre

Questions connexes