SELECT SalesOrderID, 
DENSE_RANK() OVER (ORDER BY
(SELECT COUNT(*) FROM Sales.SalesOrderDetail WHERE
SalesOrderID = O.SalesOrderID)) AS [Line Item Rank],
(SELECT COUNT(*) FROM Sales.SalesOrderDetail WHERE
SalesOrderID = O.SalesOrderID) AS [Line Item Count]
FROM Sales.SalesOrderHeader O
a
b
c
