Amazon Redshift
数据库开发人员指南 (API Version 2012-12-01)
AWS 服务或AWS文档中描述的功能,可能因地区/位置而异。请点击 Amazon AWS 入门,可查看中国地区的具体差异

MIN 开窗函数示例

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

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

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

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

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