VeloDB Cloud
SQL Manual
Functions
window-functions
WINDOW-FUNCTION-DENSE_RANK

WINDOW FUNCTION DENSE_RANK

Description

This function is used to represent rankings. Unlike RANK(), it does not allow vacancies. For example, if there are two parallel elements that should both be ranked 1, then the third rank in RANK() will be 3, but that in DENSE_RANK() will be 2.

DENSE_RANK() OVER(partition_by_clause order_by_clause)

Example

Rank column x based on the property column:

 select x, y, dense_rank() over(partition by x order by y) as rank from int_t;
 
 | x  | y    | rank     |
 |----|------|----------|
 | 1  | 1    | 1        |
 | 1  | 2    | 2        |
 | 1  | 2    | 2        |
 | 2  | 1    | 1        |
 | 2  | 2    | 2        |
 | 2  | 3    | 3        |
 | 3  | 1    | 1        |
 | 3  | 1    | 1        |
 | 3  | 2    | 2        |

Keywords

WINDOW,FUNCTION,DENSE_RANK