RANK() OVER ...

All functions > WINDOW FUNCTION > RANK() OVER ...

Returns the rank of the current row within its partition, with gaps. Rows with equal values for the ranking criteria receive the same rank.

Syntax

Diagram(
  Sequence(
    Terminal("RANK"),
    Terminal("("),Terminal(")"),
    Terminal("OVER"),
    Terminal("("),
    NonTerminal("over_clause"),
    Terminal(")"),
  )
)
ParameterTypeRequiredDescription
over_clauseOVER CLAUSEYesOVER (PARTITION BY ... ORDER BY ... [FRAME ...])

Notes

  • Assigns a rank to each row within a partition
  • Rows with equal ORDER BY values receive the same rank
  • Leaves gaps in ranking after ties (e.g., 1, 2, 2, 4)
  • Requires ORDER BY clause to determine ranking order
  • PARTITION BY creates independent ranking groups
  • First row in each partition has rank 1
  • Use WF_RANK_DENSE for ranking without gaps
  • Useful for top-N queries and percentile calculations
Last update at: 2026/03/03 16:47:38
Last updated: 2026-03-03 16:48:19