mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-24 18:50:49 +00:00
1.3 KiB
1.3 KiB
toc_priority |
---|
107 |
avgWeighted
Calculates the weighted arithmetic mean.
Syntax
avgWeighted(x, weight)
Parameters
x
— Values. Integer or floating-point.weight
— Weights of the values. Integer or floating-point.
Type of x
and weight
may be different.
Returned value
- Weighted mean.
NaN
. If all the weights are equal to 0.
Type: Float64.
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 │
└────────────────────────┘