WINDOW FUNCTION ROW_NUMBER

description

Returns a continuously increasing integer starting from 1 for each row of each Partition. Unlike RANK() and DENSE_RANK(), the value returned by ROW_NUMBER() does not repeat or appear vacant, and is continuously incremented.

  1. ROW_NUMBER() OVER(partition_by_clause order_by_clause)

example

  1. select x, y, row_number() over(partition by x order by y) as rank from int_t;
  2. | x | y | rank |
  3. |---|------|----------|
  4. | 1 | 1 | 1 |
  5. | 1 | 2 | 2 |
  6. | 1 | 2 | 3 |
  7. | 2 | 1 | 1 |
  8. | 2 | 2 | 2 |
  9. | 2 | 3 | 3 |
  10. | 3 | 1 | 1 |
  11. | 3 | 1 | 2 |
  12. | 3 | 2 | 3 |

keywords

  1. WINDOW,FUNCTION,ROW_NUMBER