postgres 窗口函数

Window Function
* row_number() bigint number of the current row within its partition, counting from 1

  • rank() bigint rank of the current row with gaps; same as row_number of its first peer

  • dense_rank() bigint rank of the current row without gaps; this function counts peer groups

  • percent_rank() double precision relative rank of the current row: (rank - 1) / (total rows - 1)

  • cume_dist() double precision relative rank of the current row: (number of rows preceding or peer with current row) / (total rows)

  • ntile(num_buckets integer) integer integer ranging from 1 to the argument value, dividing the partition as equally as possible

  • lag(value any [, offsetinteger [, default any ]]) same type as value returns value evaluated at the row that is offset rows before the current row within the partition; if there is no such row, instead return default. Bothoffset and default are evaluated with respect to the current row. If omitted, offset defaults to 1 and default to null

  • lead(value any [, offsetinteger [, default any ]]) same type as value returns value evaluated at the row that is offset rows after the current row within the partition; if there is no such row, instead return default. Bothoffset and default are evaluated with respect to the current row. If omitted, offset defaults to 1 and default to null

  • first_value(value any) same type as value returns value evaluated at the row that is the first row of the window frame

  • last_value(value any) same type as value returns value evaluated at the row that is the last row of the window frame

  • nth_value(value any, nthinteger) same type as value returns value evaluated at the row that is the nth row of the window frame (counting from 1); null if no such row

postgres=# select depname, empno, salary, row_number() over() from empsalary;
 depname | empno | salary | row_number
----------+-------+--------+------------
 develop  | 11 | 5200 | 1
 develop  | 7  | 4200 | 2
 develop  | 9  | 4500 | 3
 personel | 5  | 3500 | 4
 personel | 6  | 6500 | 5
 personel | 12 | 6500 | 6
 personel | 15 | 8900 | 7
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值