VAR_POP [analytic]

返回 窗口内组中非 null 数字集(忽略 null 值)的统计总体方差。结果的计算方法为 expressionexpression 均值之差的平方和除以剩余行数:

(SUM( expression * expression ) - SUM( expression  ) * SUM(  expression ) /   COUNT( expression )) / COUNT( expression )

行为类型

不可变

语法

VAR_POP ( expression ) OVER (
    [ window-partition-clause ]
    [ window-order-clause ]
    [ window-frame-clause ] )

参数

表达式
任何 NUMERIC 数据类型或可隐式转换为数字数据类型的任何非数字数据类型。函数返回的数据类型与参数的数字数据类型相同
OVER()
请参阅分析函数

示例

下述示例计算 2007 年 1 月商店销售事实表的累计总体方差:

=> SELECT date_ordered,
      VAR_POP(SUM(total_order_cost))
      OVER (ORDER BY date_ordered) "var_pop"
   FROM store.store_orders_fact s
   WHERE date_ordered BETWEEN '2007-01-01' AND '2007-01-31'
   GROUP BY s.date_ordered;
 date_ordered |     var_pop
--------------+------------------
 2007-01-01   |                0
 2007-01-02   |         89870400
 2007-01-03   |       3470302472
 2007-01-04   |  4466755450.6875
 2007-01-05   | 3816904780.80078
 2007-01-06   |   25438212385.25
 2007-01-07   | 22168747513.1016
 2007-01-08   | 23445191012.7344
 2007-01-09   | 39292879603.1113
 2007-01-10   | 48080574326.9609
(10 rows)

另请参阅