Professional Documents
Culture Documents
Aggregate Function
Aggregate Function
SELECT Production.ProductCategory.ProductCategoryID,
SUM( Sales.SalesOrderDetail.LineTotal) AS TotalSalesForProductCategory
FROM Sales.SalesOrderDetail CROSS JOIN
Production.ProductCategory
GROUP BY Production.ProductCategory.ProductCategoryID
HAVING Production.ProductCategory.ProductCategoryID = 1;
_____________________________________________________________
_____________________________________________________________
SELECT [Name],
AVG([ReorderPoint]) AS AverageReorderPoint
FROM[Production].[Product]
GROUP BY [Name]
ORDER BY [Name] DESC;
_____________________________________________________________
_________________________________________________________________
SELECT
[Person].[Person].BusinessEntityID,
[Bonus],
[SalesLastYear],
[SalesQuota],
SUM([SalesLastYear]) OVER (PARTITION BY [SalesQuota])
FROM [Sales].[SalesPerson]
JOIN [Person].[Person]
ON[Person].[Person].BusinessEntityID = [Sales].[SalesPerson].BusinessEntityID
_____________________________________________________________________
SELECT
[Person].[Person].BusinessEntityID,
[Bonus],
[SalesLastYear],
[SalesQuota],
COUNT(*) OVER (PARTITION BY [SalesQuota])
FROM [Sales].[SalesPerson]
JOIN [Person].[Person]
ON[Person].[Person].BusinessEntityID = [Sales].[SalesPerson].BusinessEntityID
__________________________________________________________________________
______________________________________________________________________