ランキング機能を使用できます:
WITH CTE AS
(
SELECT products, company, revenue, units,
MaxRevenue = MAX(revenue) OVER (PARTITION BY products),
MinRevenue = MIN(revenue) OVER (PARTITION BY products),
AvgRevenue = AVG(revenue) OVER (PARTITION BY products),
STDEV_Revenue = STDEV(revenue) OVER (PARTITION BY products),
MaxUnits = MAX(units) OVER (PARTITION BY products),
MinUnits = MIN(units) OVER (PARTITION BY products),
AvgUnits = AVG(units) OVER (PARTITION BY products),
STDEV_Units = STDEV(units) OVER (PARTITION BY products),
Percent_Revenue = Max(Revenue)OVER (PARTITION BY products)/SUM(Revenue) OVER (PARTITION BY products),
ProductNum = ROW_NUMBER()OVER(PARTITION BY products ORDER BY products)
FROM dbo.TableName
)
SELECT * FROM CTE
WHERE ProductNum = 1