avgWeighted

    Syntax

    Arguments

    • — Values.
    • weight — Weights of the values.

    x and weight must both be
    Integer,
    , or
    Decimal,
    but may have different types.

    Returned value

    • NaN if all the weights are equal to 0 or the supplied weights parameter is empty.
    • Weighted mean otherwise.

    Return type is always .

    Query:

    1. SELECT avgWeighted(x, w)

    Result:

    1. ┌─avgWeighted(x, weight)─┐
    2. 8
    3. └────────────────────────┘

    Example

    Query:

    Result:

    1. ┌─avgWeighted(x, weight)─┐
    2. 8

    Query:

    1. SELECT avgWeighted(x, w)
    2. FROM values('x Int8, w Int8', (0, 0), (1, 0), (10, 0))

    Result:

    Example

    Query:

    1. CREATE table test (t UInt8) ENGINE = Memory;
    2. SELECT avgWeighted(t) FROM test

    Result:

    1. ┌─avgWeighted(x, weight)─┐
    2. └────────────────────────┘