TSRunningSum 函数

TSRunningSum 函数计算 SMALLFLOAT 或 DOUBLE PRECISION 值的运行总和。

语法

TSRunningSum(value      smallfloat, 
              num_values integer) 
returns smallfloat;

TSRunningSum(value      double precision, 
              num_values integer) 
returns double precision;
value
在运行总和内包括的输入值。
num_values
在运行总和内包括的值的数量,k

描述

运行总和是最后 k 个值的总和,其中 k 由用户提供。如果值是 NULL,会使用上一个值。

此函数是运行固定数量的元素,而非运行固定时间长度;因此,它可能不适用于非常规时间系列。

只有在 Apply 函数内使用时此函数才有用。

返回结果

最后 k 个值的 SMALLFLOAT 或 DOUBLE PRECISION 运行总和。

示例

以下函数计算量积累百分比ae 表示的列分别是:highlowclosevolumenumber_of_days
create function VAP(a float, b float,c float,d float, e int) returns int;
return cast(100 * TSRunningSum(d * ((c - b) - (a - c))/
(.0001 + a - b), e)/(.0001 + TSRunningSum(d,e)) as int);
end function;