Returns the rank of the current row within its partition, with gaps, taking the highest row number among tied peers rather than the lowest.
Syntax
1modified_rank()OVER([ PARTITION BY <expression>[, ...]]ORDER BY<expression>[, ...])
Arguments
Required
None.
Optional
PARTITION BY <expression>: Divides the rows into partitions. modified_rank is computed independently within each partition. Without PARTITION BY, all rows are treated as a single partition.
ORDER BY <expression>: Determines the order used to compute the rank within each partition. modified_rank requires ORDER BY to produce a meaningful result.
Returns
Returns a bigint.
Considerations
modified_rank differs from RANK in how it handles ties: for a group of tied peer rows, modified_rank assigns the rank equal to the position of the tied group’s last (highest-numbered) peer, while rank assigns the position of the group’s first (lowest-numbered) peer.
Like rank, modified_rank leaves gaps in the sequence after a tie. This differs from DENSE_RANK, which never has gaps.
For a row with no ties, rank and modified_rank return the same value.
For general OVER clause syntax, including PARTITION BY, ORDER BY, and frame clauses, see Window Functions.
To reuse a window definition across multiple function calls, define it once in a WINDOW clause. See SELECT.
Examples
Compare RANK and MODIFIED_RANK
Contrast how rank and modified_rank handle tied salaries within each department.
1SELECT2 depname,3 rank()OVER(PARTITION BY depname ORDER BY salary DESC),4 modified_rank()OVER(PARTITION BY depname ORDER BY salary DESC),5 empno,6 salary7FROM empsalary8ORDER BY depname, rank;
In the develop department, empno 10 and 11 are tied at salary 5200. rank assigns them both 2 (the position of the first peer), while modified_rank assigns them both 3 (the position of the last peer).