ROW_NUMBER

The ROW_NUMBER function returns a unique row number for each row.

If you define window partitions, ROW_NUMBER starts the row numbering in each partition at 1, and increments each row by 1. If you do not specify a window partition, ROW_NUMBER numbers the complete result set from 1 to the total cardinality of the table.

The ROW_NUMBER function syntax is:

ROW_NUMBER() OVER ([PARTITION BY window partition] ORDER BY window ordering)

ROW_NUMBER does not require an argument, but you must specify the parentheses.

The PARTITION BY clause is optional. The OVER (ORDER_BY) clause cannot contain a window frame ROWS/RANGE specification.