数据仓库服务 GAUSSDB(DWS)-窗口函数:ROW_NUMBER()

时间:2024-12-06 15:12:39

ROW_NUMBER()

描述:ROW_NUMBER函数为各组内值生成连续排序序号,其中相同的值其序号也不相同。

返回值类型:BIGINT

示例:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
SELECT id, classid, score,ROW_NUMBER() OVER(ORDER BY score DESC) FROM score ORDER BY score DESC;
 id | classid | score | row_number
----+---------+-------+------------
  1 |       1 |    95 |          1
  2 |       2 |    95 |          2
  5 |       2 |    88 |          3
  3 |       2 |    85 |          4
  6 |       1 |    70 |          5
  4 |       1 |    70 |          6
(6 rows)
support.huaweicloud.com/sqlreference-910-dws/dws_06_0047.html