DENSE_RANK
Returns the rank of rows within
the partition of a result set, without any gaps in the ranking. The rank of a
row is one plus the number of distinct ranks that come before the row in
question.
Example:
USE AdventureWorks2012;
GO
SELECT
i.ProductID,
p.Name,
i.LocationID,
i.Quantity
,DENSE_RANK() OVER
(PARTITION BY i.LocationID ORDER BY i.Quantity DESC) AS
Rank
FROM
Production.ProductInventory AS i
INNER JOIN
Production.Product AS p ON
i.ProductID = p.ProductID
WHERE
i.LocationID BETWEEN 3 AND 4
ORDER BY
i.LocationID;
GO
No comments :
Post a Comment