Files
playbook/skills/tsl-api-reference/references/codegen/builtin/ts_sql.md
T
2026-08-14 17:15:41 +08:00

56 KiB

TS-SQL / 聚集函数

correlOf(expression_1, expression_2, bool_condition_exp, n, moving_first, cache_id)

声明:function

计算两个表达式的相关系数

参数 类型 说明
expression_1 t_expression 第一个数值表达式,可使用 DISTINCT 去重
expression_2 t_expression 第二个数值表达式
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:计算两列数据的相关系数

rows := array(
    ("X": 1, "Y": 2),
    ("X": 2, "Y": 4),
    ("X": 3, "Y": 5),
    ("X": 4, "Y": 8)
);
return vselect correlOf(["Y"], ["X"]) from rows end;
// 输出:0.981155781039212

covOf(expression_1, expression_2, bool_condition_exp, n, moving_first, cache_id)

声明:function

计算两个表达式的协方差

参数 类型 说明
expression_1 t_expression 第一个数值表达式,可使用 DISTINCT 去重
expression_2 t_expression 第二个数值表达式
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:计算两列数据的协方差

rows := array(
    ("X": 1, "Y": 2),
    ("X": 2, "Y": 4),
    ("X": 3, "Y": 5),
    ("X": 4, "Y": 8)
);
return vselect covOf(["Y"], ["X"]) from rows end;
// 输出:2.375

interceptOf(expression_1, expression_2, bool_condition_exp, n, moving_first, cache_id)

声明:function

计算以第一个表达式为因变量、第二个表达式为自变量的线性回归截距

参数 类型 说明
expression_1 t_expression 因变量表达式,可使用 DISTINCT 去重
expression_2 t_expression 自变量表达式
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:计算线性回归截距

rows := array(
    ("X": 1, "Y": 2),
    ("X": 2, "Y": 4),
    ("X": 3, "Y": 5),
    ("X": 4, "Y": 8)
);
return vselect interceptOf(["Y"], ["X"]) from rows end;
// 输出:0

percentRankOf(expression, x, bool_condition_exp, n, moving_first, cache_id)

声明:function

计算指定值在数值集合中的百分比排位,最小值为 0,最大值为 1

参数 类型 说明
expression t_expression 数值表达式,可使用 DISTINCT 去重
x real 要计算排位的数值
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:计算数值的百分比排位

rows := array(10, 6, 2, 1, 9);
return vselect percentRankOf(thisRow, 2) from rows end;
// 输出:0.25

rsqOf(expression_1, expression_2, bool_condition_exp, n, moving_first, cache_id)

声明:function

计算两个表达式的乘积矩相关系数平方

参数 类型 说明
expression_1 t_expression 第一个数值表达式,可使用 DISTINCT 去重
expression_2 t_expression 第二个数值表达式
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:计算乘积矩相关系数平方

rows := array(
    ("X": 1, "Y": 2),
    ("X": 2, "Y": 4),
    ("X": 3, "Y": 5),
    ("X": 4, "Y": 8)
);
return vselect rsqOf(["Y"], ["X"]) from rows end;
// 输出:0.962666666666667

skewOf(expression, bool_condition_exp, n, moving_first, cache_id)

声明:function

计算数值表达式的样本偏度,空值不参与统计

参数 类型 说明
expression t_expression 数值表达式,可使用 DISTINCT 去重
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:计算样本偏度

rows := array(("A": 5), ("A": 5), ("A": 9), ("A": 7));
return vselect skewOf(["A"]) from rows end;
// 输出:0.854563038327971

slopeAndInterceptOf(expression_1, expression_2, bool_condition_exp, n, moving_first, cache_id)

声明:function

计算线性回归斜率和截距,返回数组依次包含斜率与截距

参数 类型 说明
expression_1 t_expression 因变量表达式,可使用 DISTINCT 去重
expression_2 t_expression 自变量表达式
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:array

示例

范例01:计算线性回归斜率和截距

rows := array(
    ("X": 1, "Y": 2),
    ("X": 2, "Y": 4),
    ("X": 3, "Y": 5),
    ("X": 4, "Y": 8)
);
return vselect slopeAndInterceptOf(["Y"], ["X"]) from rows end;
// 输出:array(1.9,0.0)

slopeOf(expression_1, expression_2, bool_condition_exp, n, moving_first, cache_id)

声明:function

计算以第一个表达式为因变量、第二个表达式为自变量的线性回归斜率

参数 类型 说明
expression_1 t_expression 因变量表达式,可使用 DISTINCT 去重
expression_2 t_expression 自变量表达式
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:计算线性回归斜率

rows := array(
    ("X": 1, "Y": 2),
    ("X": 2, "Y": 4),
    ("X": 3, "Y": 5),
    ("X": 4, "Y": 8)
);
return vselect slopeOf(["Y"], ["X"]) from rows end;
// 输出:1.9

steyxOf(expression_1, expression_2, bool_condition_exp, n, moving_first, cache_id)

声明:function

计算线性回归预测值的标准误差

参数 类型 说明
expression_1 t_expression 因变量表达式,可使用 DISTINCT 去重
expression_2 t_expression 自变量表达式
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:计算线性回归标准误差

rows := array(
    ("X": 1, "Y": 2),
    ("X": 2, "Y": 4),
    ("X": 3, "Y": 5),
    ("X": 4, "Y": 8)
);
return vselect steyxOf(["Y"], ["X"]) from rows end;
// 输出:0.591607978309961

checksumOf(expression, ...)

声明:function

计算当前行一个或多个表达式的校验值,表达式顺序会影响结果

参数 类型 说明
expression t_expression 第一个参与校验的表达式,使用 * 时包含当前行全部字段
... t_expression 可选。继续参与校验的表达式

返回:integer

示例

范例01:计算两列组成的行校验值

rows := array(("A": 1, "B": 2), ("A": 3, "B": 4));
result := vselect checksumOf(["A"], ["B"]) from rows end;
echo trim(toStn(result)), "\n";
// 输出:1945464334

countOf(expression)

声明:function

统计当前组中表达式的非空值数量,省略表达式时统计全部行

参数 类型 说明
expression t_expression 可选。要统计的表达式,省略或使用 * 时统计全部行

返回:integer

示例

范例01:统计非空值数量

rows := array(
    ("A": 1, "B": 2, "C": 7),
    ("A": nil, "B": 3, "C": 12),
    ("A": 4, "B": 20, "C": 34)
);
result := vselect countOf(["A"]) from rows end;
echo trim(toStn(result)), "\n";
// 输出:2

refOf(expression, n, bool_condition_exp)

声明:function

返回当前行之前或之后指定位置的表达式值

参数 类型 说明
expression t_expression 要引用的表达式
n integer 相对当前行的偏移量,正数向前,负数向后,0 表示当前行
bool_condition_exp t_expression 可选。只在条件为真的行中计算相对位置

返回:any

示例

范例01:按条件引用前两行的值

rows := array(
    ("A": 5, "B": 1, "C": 34),
    ("A": 6, "B": 2, "C": 34),
    ("A": 3, "B": 4, "C": 34),
    ("A": 2, "B": 2, "C": 34),
    ("A": 7, "B": 8, "C": 34),
    ("A": -1, "B": 59, "C": 34),
    ("A": 1, "B": 18, "C": 34),
    ("A": 9, "B": 1, "C": 34),
    ("A": 2, "B": 0, "C": 34),
    ("A": 4, "B": 18, "C": 34)
);
result := select ["A"], refOf(["A"], 2, ["A"] > 2) as "refA" from rows end;
echo trim(toStn(result)), "\n";
// 输出:
// array(
// ("A":5,"refA":0),
// ("A":6,"refA":0),
// ("A":3,"refA":5),
// ("A":2,"refA":6),
// ("A":7,"refA":6),
// ("A":-1,"refA":3),
// ("A":1,"refA":3),
// ("A":9,"refA":3),
// ("A":2,"refA":7),
// ("A":4,"refA":7))

countIfOf(expression, n, moving_first, cache_id)

声明:function

统计当前组中表达式为真的行数

参数 类型 说明
expression t_expression 要统计的布尔表达式
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。保留参数,当前不影响统计方式
cache_id string 可选。时间序列统计缓存标识

返回:integer

示例

范例01:统计大于指定值的行数

rows := array(
    ("A": 6, "B": 20, "C": 34),
    ("A": 5, "B": 20, "C": 34),
    ("A": 9, "B": 20, "C": 34),
    ("A": 2, "B": 20, "C": 34),
    ("A": 7, "B": 18, "C": 34)
);
result := vselect countIfOf(["A"] > 4) from rows end;
echo trim(toStn(result)), "\n";
// 输出:4

avgOf(expression, bool_condition_exp, n, moving_first, cache_id)

声明:function

计算数值表达式的算术平均值,空值不参与统计

参数 类型 说明
expression t_expression 参与统计的表达式,可使用 DISTINCT 去重
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:计算去重后的算术平均值

rows := array(
    ("A": 5, "B": 20, "C": 34),
    ("A": 5, "B": 20, "C": 34),
    ("A": 7, "B": 18, "C": 34)
);
result := vselect avgOf(distinct ["A"]) from rows end;
echo trim(toStn(result)), "\n";
// 输出:6.0

emaOf(expression, bool_condition_exp, n, moving_first, cache_id)

声明:function

计算数值表达式的指数移动平均值,不支持空值

参数 类型 说明
expression t_expression 参与计算的数值表达式
bool_condition_exp t_expression 用于筛选参与计算行的布尔表达式
n integer 指数移动平均周期
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:计算两期指数移动平均值

rows := array(
    ("A": 6, "B": 20, "C": 34),
    ("A": 5, "B": 20, "C": 34),
    ("A": 9, "B": 20, "C": 34),
    ("A": 2, "B": 20, "C": 34),
    ("A": 7, "B": 18, "C": 34)
);
result := select emaOf(["A"], true, 2) from rows end;
echo trim(toStn(result)), "\n";
// 输出:
// array(
// ("Expr1":6.0),
// ("Expr1":5.33333333333333),
// ("Expr1":7.77777777777778),
// ("Expr1":3.92592592592593),
// ("Expr1":5.97530864197531))

smaOf(expression, m, bool_condition_exp, n, moving_first, cache_id)

声明:function

计算数值表达式的平滑移动平均值,不支持空值

参数 类型 说明
expression t_expression 参与计算的数值表达式
m integer 平滑权重参数
bool_condition_exp t_expression 用于筛选参与计算行的布尔表达式
n integer 平滑移动平均周期
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:计算三期平滑移动平均值

rows := array(
    ("A": 6, "B": 20, "C": 34),
    ("A": 5, "B": 20, "C": 34),
    ("A": 9, "B": 20, "C": 34),
    ("A": 2, "B": 20, "C": 34),
    ("A": 7, "B": 18, "C": 34)
);
result := select smaOf(["A"], 2, true, 3) from rows end;
echo trim(toStn(result)), "\n";
// 输出:
// array(
// ("Expr1":6.0),
// ("Expr1":5.33333333333333),
// ("Expr1":7.77777777777778),
// ("Expr1":3.92592592592593),
// ("Expr1":5.97530864197531))

harMeanOf(expression, bool_condition_exp, n, moving_first, cache_id)

声明:function

计算数值表达式的调和平均值,空值不参与统计

参数 类型 说明
expression t_expression 参与统计的表达式,可使用 DISTINCT 去重
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:计算去重后的调和平均值

rows := array(
    ("A": 5, "B": 20, "C": 34),
    ("A": 5, "B": 20, "C": 34),
    ("A": 7, "B": 18, "C": 34)
);
result := vselect harMeanOf(distinct ["A"]) from rows end;
echo trim(toStn(result)), "\n";
// 输出:5.83333333333333

geoMeanOf(expression, bool_condition_exp, n, moving_first, cache_id)

声明:function

计算数值表达式的几何平均值,空值不参与统计

参数 类型 说明
expression t_expression 参与统计的表达式,可使用 DISTINCT 去重
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:计算去重后的几何平均值

rows := array(
    ("A": 5, "B": 20, "C": 34),
    ("A": 5, "B": 20, "C": 34),
    ("A": 7, "B": 18, "C": 34)
);
result := vselect geoMeanOf(distinct ["A"]) from rows end;
echo trim(toStn(result)), "\n";
// 输出:5.91607978309962

sumOf(expression, bool_condition_exp, n, moving_first, cache_id)

声明:function

计算数值表达式的总和,空值不参与统计

参数 类型 说明
expression t_expression 参与统计的表达式,可使用 DISTINCT 去重
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:计算去重后的总和

rows := array(
    ("A": 5, "B": 20, "C": 34),
    ("A": 5, "B": 20, "C": 34),
    ("A": 7, "B": 18, "C": 34)
);
result := vselect sumOf(distinct ["A"]) from rows end;
echo trim(toStn(result)), "\n";
// 输出:12.0

minOf(expression, bool_condition_exp, n, moving_first, cache_id)

声明:function

返回数值表达式的最小值

参数 类型 说明
expression t_expression 参与统计的表达式,可使用 DISTINCT 去重
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:返回满足条件的最小值

rows := array(
    ("A": 5, "B": 20, "C": 34),
    ("A": 5, "B": 20, "C": 34),
    ("A": 9, "B": 20, "C": 34),
    ("A": 7, "B": 18, "C": 34)
);
result := vselect minOf(["A"], ["A"] > 6) from rows end;
echo trim(toStn(result)), "\n";
// 输出:7.0

maxOf(expression, bool_condition_exp, n, moving_first, cache_id)

声明:function

返回数值表达式的最大值

参数 类型 说明
expression t_expression 参与统计的表达式,可使用 DISTINCT 去重
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:返回满足条件的最大值

rows := array(
    ("A": 5, "B": 20, "C": 34),
    ("A": 5, "B": 20, "C": 34),
    ("A": 9, "B": 20, "C": 34),
    ("A": 7, "B": 18, "C": 34)
);
result := vselect maxOf(["A"], ["A"] > 6) from rows end;
echo trim(toStn(result)), "\n";
// 输出:9.0

refMinOf(expression, id_string)

声明:function

返回 minOf 最小值所在行的另一个表达式值

参数 类型 说明
expression t_expression 要从最小值所在行读取的表达式
id_string string 可选。对应 minOf 使用的缓存标识

返回:any

示例

范例01:读取两列最小值所在行的关联值

rows := array(
    ("A": 6, "B": 20, "C": 34),
    ("A": 5, "B": 20, "C": 34),
    ("A": 9, "B": 2, "C": 34),
    ("A": 2, "B": 20, "C": 34),
    ("A": 7, "B": 18, "C": 34)
);
result := select
    minOf(["A"], true, nil, true, "<MAXMIN=minA/>"),
    minOf(["B"], true, nil, true, "<MAXMIN=minB/>"),
    refMinOf(["B"], "minA"),
    refMinOf(["A"], "minB")
from rows end;
echo trim(toStn(result)), "\n";
// 输出:
// array(
// ("Expr1":2.0,"Expr2":2.0,"Expr3":20,"Expr4":9))

refMaxOf(expression, id_string)

声明:function

返回 maxOf 最大值所在行的另一个表达式值

参数 类型 说明
expression t_expression 要从最大值所在行读取的表达式
id_string string 可选。对应 maxOf 使用的缓存标识

返回:any

示例

范例01:读取两列最大值所在行的关联值

rows := array(
    ("A": 6, "B": 20, "C": 34),
    ("A": 5, "B": 20, "C": 34),
    ("A": 9, "B": 2, "C": 34),
    ("A": 2, "B": 20, "C": 34),
    ("A": 7, "B": 18, "C": 34)
);
result := select
    maxOf(["A"], true, nil, true, "<MAXMIN=maxA/>"),
    maxOf(["B"], true, nil, true, "<MAXMIN=maxB/>"),
    refMaxOf(["B"], "maxA"),
    refMaxOf(["A"], "maxB")
from rows end;
echo trim(toStn(result)), "\n";
// 输出:
// array(
// ("Expr1":9.0,"Expr2":20.0,"Expr3":2,"Expr4":6))

modeOf(expression, bool_condition_exp, n, moving_first, cache_id)

声明:function

返回数值表达式中出现频率最高的值

参数 类型 说明
expression t_expression 参与统计的表达式,可使用 DISTINCT 去重
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:计算众数

rows := array(
    ("A": 5, "B": 20, "C": 34),
    ("A": 5, "B": 20, "C": 34),
    ("A": 9, "B": 20, "C": 34),
    ("A": 7, "B": 18, "C": 34)
);
result := vselect modeOf(["A"]) from rows end;
echo trim(toStn(result)), "\n";
// 输出:5.0

medianOf(expression, bool_condition_exp, n, moving_first, cache_id)

声明:function

返回数值表达式的中位数,偶数个值时返回中间两值的平均值

参数 类型 说明
expression t_expression 参与统计的表达式,可使用 DISTINCT 去重
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:计算中位数

rows := array(
    ("A": 5, "B": 20, "C": 34),
    ("A": 5, "B": 20, "C": 34),
    ("A": 9, "B": 20, "C": 34),
    ("A": 7, "B": 18, "C": 34)
);
result := vselect medianOf(["A"]) from rows end;
echo trim(toStn(result)), "\n";
// 输出:6.0

stdevOf(expression, bool_condition_exp, n, moving_first, cache_id)

声明:function

计算数值表达式的样本标准差,空值不参与统计

参数 类型 说明
expression t_expression 参与统计的表达式,可使用 DISTINCT 去重
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:计算样本标准差

rows := array(
    ("A": 5, "B": 20, "C": 34),
    ("A": 5, "B": 20, "C": 34),
    ("A": 9, "B": 20, "C": 34),
    ("A": 7, "B": 18, "C": 34)
);
result := vselect stdevOf(["A"]) from rows end;
echo trim(toStn(result)), "\n";
// 输出:1.91485421551268

stdevpOf(expression, bool_condition_exp, n, moving_first, cache_id)

声明:function

计算数值表达式的总体标准差,空值不参与统计

参数 类型 说明
expression t_expression 参与统计的表达式,可使用 DISTINCT 去重
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:计算总体标准差

rows := array(
    ("A": 5, "B": 20, "C": 34),
    ("A": 5, "B": 20, "C": 34),
    ("A": 9, "B": 20, "C": 34),
    ("A": 7, "B": 18, "C": 34)
);
result := vselect stdevpOf(["A"]) from rows end;
echo trim(toStn(result)), "\n";
// 输出:1.6583123951777

varOf(expression, bool_condition_exp, n, moving_first, cache_id)

声明:function

计算数值表达式的样本方差,空值不参与统计

参数 类型 说明
expression t_expression 参与统计的表达式,可使用 DISTINCT 去重
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:计算样本方差

rows := array(
    ("A": 5, "B": 20, "C": 34),
    ("A": 5, "B": 20, "C": 34),
    ("A": 9, "B": 20, "C": 34),
    ("A": 7, "B": 18, "C": 34)
);
result := vselect varOf(["A"]) from rows end;
echo trim(toStn(result)), "\n";
// 输出:3.66666666666667

varpOf(expression, bool_condition_exp, n, moving_first, cache_id)

声明:function

计算数值表达式的总体方差,空值不参与统计

参数 类型 说明
expression t_expression 参与统计的表达式,可使用 DISTINCT 去重
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:计算总体方差

rows := array(
    ("A": 5, "B": 20, "C": 34),
    ("A": 5, "B": 20, "C": 34),
    ("A": 9, "B": 20, "C": 34),
    ("A": 7, "B": 18, "C": 34)
);
result := vselect varpOf(["A"]) from rows end;
echo trim(toStn(result)), "\n";
// 输出:2.75

totalVarOf(expression, bool_condition_exp, n, moving_first, cache_id)

声明:function

计算数值表达式各值与均值之差的平方和

参数 类型 说明
expression t_expression 参与统计的表达式,可使用 DISTINCT 去重
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:计算总方差

rows := array(
    ("A": 5, "B": 20, "C": 34),
    ("A": 5, "B": 20, "C": 34),
    ("A": 9, "B": 20, "C": 34),
    ("A": 7, "B": 18, "C": 34)
);
result := vselect totalVarOf(["A"]) from rows end;
echo trim(toStn(result)), "\n";
// 输出:11.0

aveDevOf(expression, bool_condition_exp, n, moving_first, cache_id)

声明:function

计算数值表达式各值与均值之差的绝对值平均数

参数 类型 说明
expression t_expression 参与统计的表达式,可使用 DISTINCT 去重
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:计算平均绝对偏差

rows := array(
    ("A": 5, "B": 20, "C": 34),
    ("A": 5, "B": 20, "C": 34),
    ("A": 9, "B": 20, "C": 34),
    ("A": 7, "B": 18, "C": 34)
);
result := vselect aveDevOf(["A"]) from rows end;
echo trim(toStn(result)), "\n";
// 输出:1.5

devSqOf(expression, bool_condition_exp, n, moving_first, cache_id)

声明:function

计算数值表达式各值与均值之差的平方和

参数 类型 说明
expression t_expression 参与统计的表达式,可使用 DISTINCT 去重
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:计算偏差平方和

rows := array(
    ("A": 5, "B": 20, "C": 34),
    ("A": 5, "B": 20, "C": 34),
    ("A": 9, "B": 20, "C": 34),
    ("A": 7, "B": 18, "C": 34)
);
result := vselect devSqOf(["A"]) from rows end;
echo trim(toStn(result)), "\n";
// 输出:11.0

normOf(expression, bool_condition_exp, n, moving_first, cache_id)

声明:function

计算数值表达式平方和的平方根

参数 类型 说明
expression t_expression 参与统计的表达式,可使用 DISTINCT 去重
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:计算二范数

rows := array(
    ("A": 5, "B": 20, "C": 34),
    ("A": 5, "B": 20, "C": 34),
    ("A": 9, "B": 20, "C": 34),
    ("A": 7, "B": 18, "C": 34)
);
result := vselect normOf(["A"]) from rows end;
echo trim(toStn(result)), "\n";
// 输出:13.4164078649987

skew2Of(expression, bool_condition_exp, n, moving_first, cache_id)

声明:function

计算与矩阵算法兼容的总体偏度

参数 类型 说明
expression t_expression 参与统计的表达式,可使用 DISTINCT 去重
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:计算总体偏度

rows := array(
    ("A": 5, "B": 20, "C": 34),
    ("A": 5, "B": 20, "C": 34),
    ("A": 9, "B": 20, "C": 34),
    ("A": 7, "B": 18, "C": 34)
);
result := vselect skew2Of(["A"]) from rows end;
echo trim(toStn(result)), "\n";
// 输出:0.493382200218159

kurtosisOf(expression, bool_condition_exp, n, moving_first, cache_id)

声明:function

计算与表格算法兼容的总体峰度

参数 类型 说明
expression t_expression 参与统计的表达式,可使用 DISTINCT 去重
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:计算表格算法峰度

rows := array(
    ("A": 5, "B": 20, "C": 34),
    ("A": 5, "B": 20, "C": 34),
    ("A": 9, "B": 20, "C": 34),
    ("A": 7, "B": 18, "C": 34)
);
result := vselect kurtosisOf(["A"]) from rows end;
echo trim(toStn(result)), "\n";
// 输出:-1.28925619834711

kurtosis2Of(expression, bool_condition_exp, n, moving_first, cache_id)

声明:function

计算与矩阵算法兼容的总体峰度

参数 类型 说明
expression t_expression 参与统计的表达式,可使用 DISTINCT 去重
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:计算矩阵算法峰度

rows := array(
    ("A": 5, "B": 20, "C": 34),
    ("A": 5, "B": 20, "C": 34),
    ("A": 9, "B": 20, "C": 34),
    ("A": 7, "B": 18, "C": 34)
);
result := vselect kurtosis2Of(["A"]) from rows end;
echo trim(toStn(result)), "\n";
// 输出:1.62809917355372

largeOf(expression, k, bool_condition_exp, n, moving_first, cache_id)

声明:function

返回数值表达式中第 k 个最大值

参数 类型 说明
expression t_expression 参与排序的数值表达式
k integer 从大到小的序号,从 1 开始
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:返回第二大值

rows := array(
    ("A": 5, "B": 20, "C": 34),
    ("A": 5, "B": 20, "C": 34),
    ("A": 9, "B": 20, "C": 34),
    ("A": 7, "B": 18, "C": 34)
);
result := vselect largeOf(["A"], 2) from rows end;
echo trim(toStn(result)), "\n";
// 输出:7.0

smallOf(expression, k, bool_condition_exp, n, moving_first, cache_id)

声明:function

返回数值表达式中第 k 个最小值

参数 类型 说明
expression t_expression 参与排序的数值表达式
k integer 从小到大的序号,从 1 开始
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:返回第二小值

rows := array(
    ("A": 5, "B": 20, "C": 34),
    ("A": 5, "B": 20, "C": 34),
    ("A": 9, "B": 20, "C": 34),
    ("A": 7, "B": 18, "C": 34)
);
result := vselect smallOf(["A"], 2) from rows end;
echo trim(toStn(result)), "\n";
// 输出:5.0

percentileOf(expression, k, bool_condition_exp, n, moving_first, cache_id)

声明:function

返回数值表达式指定百分位位置的值

参数 类型 说明
expression t_expression 参与计算的数值表达式
k real 百分位位置,取值范围为 01
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:计算三分之一分位值

rows := array(
    ("A": 5, "B": 20, "C": 34),
    ("A": 5, "B": 20, "C": 34),
    ("A": 9, "B": 20, "C": 34),
    ("A": 7, "B": 18, "C": 34)
);
result := vselect percentileOf(["A"], 1 / 3) from rows end;
echo trim(toStn(result)), "\n";
// 输出:5.0

quartileOf(expression, k, bool_condition_exp, n, moving_first, cache_id)

声明:function

返回数值表达式指定四分位位置的值

参数 类型 说明
expression t_expression 参与计算的数值表达式
k integer 四分位位置,取值为 04
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:返回最小四分位值

rows := array(
    ("A": 5, "B": 20, "C": 34),
    ("A": 5, "B": 20, "C": 34),
    ("A": 9, "B": 20, "C": 34),
    ("A": 7, "B": 18, "C": 34)
);
result := vselect quartileOf(["A"], 0) from rows end;
echo trim(toStn(result)), "\n";
// 输出:5.0

rankOf(expression, x, bool_condition_exp, n, moving_first, cache_id)

声明:function

返回指定数值在表达式结果中按从大到小排列的名次

参数 类型 说明
expression t_expression 参与排序的数值表达式
x real 要计算排位的数值
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:计算指定值的降序名次

rows := array(
    ("A": 5, "B": 20, "C": 34),
    ("A": 5, "B": 20, "C": 34),
    ("A": 9, "B": 20, "C": 34),
    ("A": 7, "B": 18, "C": 34)
);
result := vselect rankOf(["A"], 7) from rows end;
echo trim(toStn(result)), "\n";
// 输出:2

trimMeanOf(expression, k, bool_condition_exp, n, moving_first, cache_id)

声明:function

从数值表达式两端剔除指定比例的数据后计算平均值

参数 类型 说明
expression t_expression 参与计算的数值表达式
k real 从首尾剔除的数据比例
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:计算截尾平均值

rows := array(
    ("A": 5, "B": 20, "C": 34),
    ("A": 5, "B": 20, "C": 34),
    ("A": 9, "B": 20, "C": 34),
    ("A": 7, "B": 18, "C": 34)
);
result := vselect trimMeanOf(["A"], 0.2) from rows end;
echo trim(toStn(result)), "\n";
// 输出:6.5

frequencyOf(expression, calc_array, bool_condition_exp, n, moving_first, cache_id)

声明:function

统计数值表达式落入各区间的频数

参数 类型 说明
expression t_expression 参与分组的数值表达式
calc_array array 按升序给出的区间上界数组
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:array

示例

范例01:按一个区间上界统计频数

rows := array(
    ("A": 5, "B": 20, "C": 34),
    ("A": 5, "B": 20, "C": 34),
    ("A": 9, "B": 20, "C": 34),
    ("A": 7, "B": 18, "C": 34)
);
result := vselect frequencyOf(["A"], array(6)) from rows end;
echo trim(toStn(result)), "\n";
// 输出:array(2,2)

productOf(expression, bool_condition_exp, n, moving_first, cache_id)

声明:function

计算数值表达式中全部值的乘积

参数 类型 说明
expression t_expression 参与统计的表达式,可使用 DISTINCT 去重
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:real

示例

范例01:计算全部值的乘积

rows := array(
    ("A": 5, "B": 20, "C": 34),
    ("A": 5, "B": 20, "C": 34),
    ("A": 9, "B": 20, "C": 34),
    ("A": 7, "B": 18, "C": 34)
);
result := vselect productOf(["A"]) from rows end;
echo trim(toStn(result)), "\n";
// 输出:1575.0

checksum_aggOf(expression, bool_condition_exp, n, moving_first, cache_id)

声明:function

计算数值表达式全部值的聚集校验和

参数 类型 说明
expression t_expression 参与统计的表达式,可使用 DISTINCT 去重
bool_condition_exp t_expression 可选。只统计条件为真的行
n integer 可选。相对当前行参与统计的记录数,负数表示向后取记录
moving_first bool 可选。是否先限定最近 n 条记录再应用条件
cache_id string 可选。时间序列统计缓存标识

返回:integer

示例

范例01:计算一列的聚集校验和

rows := array(
    ("A": 6, "B": 20, "C": 34),
    ("A": 5, "B": 20, "C": 34),
    ("A": 9, "B": 2, "C": 34),
    ("A": 2, "B": 20, "C": 34),
    ("A": 7, "B": 18, "C": 34)
);
result := vselect checksum_aggOf(["C"]) from rows end;
echo trim(toStn(result)), "\n";
// 输出:1849359852