T-SQL Tutorial

T-SQL PERCENT_RANK


The T-SQL PERCENT_RANK function is an analytic function and is used in SQL Server database to calculate the relative rank of a row within a group of rows.

PERCENT_RANK Syntax


PERCENT_RANK( )
OVER ( [ partition_by_clause ] order_by_clause )



PERCENT_RANK Example


select b.*,
PERCENT_RANK() OVER (ORDER BY b.price ) AS PctRank
from books b;