avgif()(聚合函数)avgif() (aggregation function)

计算谓词的计算结果为 true 的组内 Expr 的平均值Calculates the average of Expr across the group for which Predicate evaluates to true.

  • 只能在 summarize 内的聚合上下文中使用Can only be used in context of aggregation inside summarize

语法Syntax

summarize avgif(Expr, Predicate)summarize avgif(Expr, Predicate)

参数Arguments

  • Expr:用于聚合计算的表达式。Expr : Expression that will be used for aggregation calculation. 具有 null 值的记录将被忽略,并且不包括在计算中。Records with null values are ignored and not included in the calculation.
  • 谓词 :谓词如果为 true,则 Expr 计算值将添加到平均值。Predicate : predicate that if true, the Expr calculated value will be added to the average.

返回Returns

谓词计算结果为 true 的组内 Expr 的平均值 。The average value of Expr across the group where Predicate evaluates to true.

示例Examples

range x from 1 to 100 step 1
| summarize avgif(x, x%2 == 0)
avgif_xavgif_x
5151