DENSE_RANK
functionsupportedCore SQL functionsReturns the rank of a value within a group of values, without gaps in the ranks. The rank value starts at 1 and continues up sequentially. If two values are the same, they have the same rank.
Syntax
supportedpartialnot supportednot scored
DENSE_RANK() OVER ( [ PARTITION BY <expr1> ]
ORDER BY <expr2> [ { ASC | DESC } ] [ NULLS { FIRST | LAST } ] [ <window_frame> ] )
Usage notes
- expr1 The column or expression to partition the window by. For example, suppose that within each state or province, you want to rank farmers in order by the amount of corn they produced. In this case, you partition by state. If you want only a single group (e.g. you want to rank all farmers in the U.S. regardless of which state they live in), then omit the PARTITION BY clause.
- expr2 The column or expression to order (rank) by. For example, if you’re ranking farmers to see who produced the most corn (within their state), then you would use the bushels_produced column. For details, see Examples (in this topic).
- Tie values result in the same rank value, but unlike RANK, they do not result in gaps in the sequence.