博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
postgres 窗口函数
阅读量:2342 次
发布时间:2019-05-10

本文共 2046 字,大约阅读时间需要 6 分钟。

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

转载地址:http://keyvb.baihongyu.com/

你可能感兴趣的文章
log4j2.xml实用例子
查看>>
Dockerfile中的CMD和ENTRYPOINT有什么区别?
查看>>
jQuery提示和技巧
查看>>
是否可以在Python中将长行分成多行[重复]
查看>>
命令行上的Node.js版本? (不是REPL)
查看>>
你什么时候使用Builder模式? [关闭]
查看>>
在jQuery中每5秒调用一次函数的最简单方法是什么? [重复]
查看>>
Angular 2+中的ngShow和ngHide等效于什么?
查看>>
如何将Java String转换为byte []?
查看>>
@Transactional注释在哪里?
查看>>
找不到Gradle DSL方法:'runProguard'
查看>>
AngularJS ngClass条件
查看>>
连字符分隔的大小写是什么? [关闭]
查看>>
为什么Java中没有SortedList?
查看>>
在Go中表示枚举的惯用方法是什么?
查看>>
如何在本地运行travis-ci
查看>>
模板中关键字“ typename”和“ class”的区别?
查看>>
在React中显示或隐藏元素
查看>>
暂存已删除的文件
查看>>
为什么需要在脚本文件的开头加上#!/ bin / bash?
查看>>