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

STDDEV_POP 和 VAR_POP 开窗函数示例

以下示例说明如何使用 STDDEV_POP 和 VAR_POP 作为开窗函数。查询计算 SALES 表中 PRICEPAID 值的总体方差和总体标准差。

Copy
select salesid, dateid, pricepaid, round(stddev_pop(pricepaid) over (order by dateid, salesid rows unbounded preceding)) as stddevpop, round(var_pop(pricepaid) over (order by dateid, salesid rows unbounded preceding)) as varpop from sales order by 2,1; salesid | dateid | pricepaid | stddevpop | varpop --------+--------+-----------+-----------+--------- 33095 | 1827 | 234.00 | 0 | 0 65082 | 1827 | 472.00 | 119 | 14161 88268 | 1827 | 836.00 | 248 | 61283 97197 | 1827 | 708.00 | 230 | 53019 110328 | 1827 | 347.00 | 223 | 49845 110917 | 1827 | 337.00 | 215 | 46159 150314 | 1827 | 688.00 | 211 | 44414 157751 | 1827 | 1730.00 | 447 | 199679 165890 | 1827 | 4192.00 | 1185 | 1403323 ...

样本标准差和样本标准方差函数可通过同一方式使用。