divide values in a Group By query

Viewed 14063

How is it possible to build a request like this (Sql Server 2008 R2) :
(I need an "Average Price" per result)

SELECT 
    CategoryId
  , SUM(Price) AS TotalPrice
  , SUM(Quantity) AS TotalQuantity
  -->, TotalPrice/TotalQuantity AS AveragePrice
FROM Products 
GROUP BY CategoryId

(if possible without recalculating one more times the two SUMs...)

2 Answers
Related