Edit

Share via


ARRAY_AVG (NoSQL query)

APPLIES TO: NoSQL

Returns the average value of elements in the specified array expression.

Syntax

ARRAY_AVG(<array_expr>)  

Arguments

Description
array_expr An array expression.

Return types

Returns a numeric expression.

Examples

The following example shows the results of using this function on arrays with numeric values.

SELECT VALUE {
    "case1": ARRAY_AVG([1, 2, 3, 4]),
    "case2": ARRAY_AVG([1.0, 2.0, 3.3, 4.7]),
    "case3": ARRAY_AVG([1, -2.7, 3, -4, undefined]),
    "case4": ARRAY_AVG(['abc', 'ABC', 'aBc', 'AbC']),
    "case5": ARRAY_AVG([12, 'abc', true, false, null, undefined])
}
[
    {
        "case1": 2.5,
        "case2": 2.75,
        "case3": -0.675
    }
]

Remarks

  • The elements in array can only be number.
  • Any undefined values are ignored.
  • This function performs a full scan.