Skip to content

Rank

Assigns a rank to each row within a partition, with gaps in the ranking when there are ties.

Category: window

Syntax:

Rank()

Returns: Integer

Context Filtering: ✓ Yes

Parameters

This function takes no parameters. The ranking is determined by the ORDER BY clause in the window specification.

Validation

  • Minimum parameters: 0
  • Maximum parameters: 0

Examples

Rank()

Returns the rank of each row based on the specified ordering. If two rows tie for rank 1, the next rank will be 3.

Rank()

When ordered by sales descending, assigns rank 1 to the highest sales, rank 2 to the next, etc. If rows 2 and 3 have the same value, both get rank 2, and the next row gets rank 4. Result: 1, 2, 2, 4, 5, ...

  • DenseRank - Assigns rank without gaps
  • PercentRank - Calculates relative rank as percentage
  • RowNumber - Assigns sequential row numbers
  • Ntile - Divides rows into groups
  • CumeDist - Calculates cumulative distribution