数据仓库服务 GAUSSDB(DWS)-窗口函数:NTILE(num_buckets integer)

时间:2024-04-18 16:25:02

NTILE(num_buckets integer)

描述:NTILE函数根据num_buckets integer将有序的数据集合平均分配到num_buckets所指定数量的桶中,并将桶号分配给每一行。分配时应尽量做到平均分配。

返回值类型:INTEGER

示例:

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