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

AVG 开窗函数示例

按日期计算销量的移动平均数;按日期 ID 和销售 ID 对结果进行排序:

Copy
select salesid, dateid, sellerid, qty, avg(qty) over (order by dateid, salesid rows unbounded preceding) as avg from winsales order by 2,1; salesid | dateid | sellerid | qty | avg ---------+------------+----------+-----+----- 30001 | 2003-08-02 | 3 | 10 | 10 10001 | 2003-12-24 | 1 | 10 | 10 10005 | 2003-12-24 | 1 | 30 | 16 40001 | 2004-01-09 | 4 | 40 | 22 10006 | 2004-01-18 | 1 | 10 | 20 20001 | 2004-02-12 | 2 | 20 | 20 40005 | 2004-02-12 | 4 | 10 | 18 20002 | 2004-02-16 | 2 | 20 | 18 30003 | 2004-04-18 | 3 | 15 | 18 30004 | 2004-04-18 | 3 | 20 | 18 30007 | 2004-09-07 | 3 | 30 | 19 (11 rows)

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