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

WINDOW FUNCTION ROW_NUMBER

Description

This function returns an integer for each row of each partition. The integers start from 1 and increase continuously. Unlike RANK() and DENSE_RANK(), ROW_NUMBER() does not return repeated values or leave any number vacant since the integers are continuous.

ROW_NUMBER() OVER(partition_by_clause order_by_clause)

Example

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

Keywords

WINDOW,FUNCTION,ROW_NUMBER