How to use Percent_Rank() Function in SQL?

PERCENT_RANK() function is used to evaluate the relative ranking of a value within a given set of values.

The syntax of the PERCENT_RANK() function:

Syntax:

PERCENT_RANK() OVER (
    [PARTITION BY partition_expression, ... ]
    ORDER BY sort_expression [ASC | DESC], ...
)

In the above syntax:

  • The PARTITION BY is an optional clause that is used with the PERCENT_RANK() function to divide rows into multiple partitions. It defaults to a single set.
  • The ORDER BY clause is used to set the order in which the resultant query is returned.
  • The PERCENT_RANK() function always returns value that is greater than 0 and less than or equal to 1.