Amazon Redshift
数据库开发人员指南 (API Version 2012-12-01)
AWS 服务或AWS文档中描述的功能,可能因地区/位置而异。点 击 Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

MAX 开窗函数示例

从数据窗口的开头显示销售 ID、数量和最大数量:

Copy
select salesid, qty, max(qty) over (order by salesid rows unbounded preceding) as max from winsales order by salesid; salesid | qty | max ---------+-----+----- 10001 | 10 | 10 10005 | 30 | 30 10006 | 10 | 30 20001 | 20 | 30 20002 | 20 | 30 30001 | 10 | 30 30003 | 15 | 30 30004 | 20 | 30 30007 | 30 | 30 40001 | 40 | 40 40005 | 10 | 40 (11 rows)

有关 WINSALES 表的说明,请参阅开窗函数示例

在受限制的框架中显示销售 ID、数量和最大数量:

Copy
select salesid, qty, max(qty) over (order by salesid rows between 2 preceding and 1 preceding) as max from winsales order by salesid; salesid | qty | max ---------+-----+----- 10001 | 10 | 10005 | 30 | 10 10006 | 10 | 30 20001 | 20 | 30 20002 | 20 | 20 30001 | 10 | 20 30003 | 15 | 20 30004 | 20 | 15 30007 | 30 | 20 40001 | 40 | 30 40005 | 10 | 40 (11 rows)