Labels

Wednesday, April 3, 2013

PERCENT_RANK

/*
PERCENT_RANK() function will returns the percentage value of rank of the element among its group.

PERCENT_RANK() function value will be

    For first element in its group, it will be 0.
    For last element in its group, it will be 1.
    For remaining elements, it will be ( No. Of Elements Before that Element ) / (Total Elements - 1)
*/

DECLARE @T TABLE

Number INT
)
INSERT INTO @T (Number)
VALUES (10),(20),(30),(50)

SELECT Number,
PERCENT_RANK() OVER (ORDER BY Number) AS PERCENTRANK
FROM @T

No comments:

Post a Comment