USE AdventureWorks2;
GO
SELECT SalesOrderID, ProductID,
OrderQty AS "Item Qty",SUM(OrderQty)
OVER(PARTITION BY SalesOrderID) AS "Total Qty",
AVG(OrderQty) OVER(PARTITION BY SalesOrderID)
AS "Average Qty",
COUNT(OrderQty) OVER(PARTITION BY SalesOrderID)
AS "Total Count",
MIN(OrderQty) OVER(PARTITION BY SalesOrderID)
AS "Minimum Count",
MAX(OrderQty) OVER(PARTITION BY SalesOrderID) AS
"Maximum Count",LineTotal,
AVG(LineTotal) OVER(PARTITION BY SalesOrderID) AS
"Average Amount",
SUM(LineTotal) OVER(PARTITION BY SalesOrderID) AS
"Total Amount",(LineTotal/SUM(LineTotal)
OVER(PARTITION BY SalesOrderID)) * 100 AS
"Percent"FROM Sales.SalesOrderDetail WHERE
SalesOrderID = 43664ORDER BY ProductID
GO |