avgWeighted
Calculates the [weighted arithmetic mean](https://en.
Calculates the weighted arithmetic mean.
Syntax
avgWeighted(x, weight)Arguments
Returned value
Returns NaN if all the weights are equal to 0 or the supplied weights parameter is empty, or the weighted mean otherwise. Float64
Examples
Usage example
SELECT avgWeighted(x, w)
FROM VALUES('x Int8, w Int8', (4, 1), (1, 0), (10, 2))┌─avgWeighted(x, w)─┐
│ 8 │
└───────────────────┘Mixed integer and float weights
SELECT avgWeighted(x, w)
FROM VALUES('x Int8, w Float64', (4, 1), (1, 0), (10, 2))┌─avgWeighted(x, w)─┐
│ 8 │
└───────────────────┘All weights are zero returns NaN
SELECT avgWeighted(x, w)
FROM VALUES('x Int8, w Int8', (0, 0), (1, 0), (10, 0))┌─avgWeighted(x, w)─┐
│ nan │
└───────────────────┘Empty table returns NaN
CREATE TABLE test (t UInt8) ENGINE = Memory;
SELECT avgWeighted(t, t) FROM test┌─avgWeighted(t, t)─┐
│ nan │
└───────────────────┘Introduced in version 20.1.