mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-24 10:40:49 +00:00
1.4 KiB
1.4 KiB
toc_priority |
---|
107 |
avgWeighted
Calculates the weighted arithmetic mean.
Syntax
avgWeighted(x, weight)
Parameters
x
— Values.weight
— Weights of the values.
x
and weight
must both be
Integer,
floating-point, or
Decimal,
but may have different types.
Returned value
NaN
. If all the weights are equal to 0.- Weighted mean otherwise.
Return type
Decimal
if both types are Decimal or if one type is Decimal and other is Integer.- Float64 otherwise.
Example
Query:
SELECT avgWeighted(x, w)
FROM values('x Int8, w Int8', (4, 1), (1, 0), (10, 2))
Result:
┌─avgWeighted(x, weight)─┐
│ 8 │
└────────────────────────┘
Example
Query:
SELECT avgWeighted(x, w)
FROM values('x Int8, w Float64', (4, 1), (1, 0), (10, 2))
Result:
┌─avgWeighted(x, weight)─┐
│ 8 │
└────────────────────────┘