Introduite dans : v20.1.0
Calcule la moyenne arithmétique pondérée.
Syntaxe
Arguments
Valeur renvoyée
Renvoie NaN si tous les poids sont égaux à 0 ou si le paramètre weight fourni est vide ; sinon, renvoie la moyenne pondérée. Float64
Exemples
Exemple d’utilisation
SELECT avgWeighted(x, w)
FROM VALUES('x Int8, w Int8', (4, 1), (1, 0), (10, 2))
┌─avgWeighted(x, w)─┐
│ 8 │
└───────────────────┘
Poids mixtes entiers et flottants
SELECT avgWeighted(x, w)
FROM VALUES('x Int8, w Float64', (4, 1), (1, 0), (10, 2))
┌─avgWeighted(x, w)─┐
│ 8 │
└───────────────────┘
Si tous les poids sont nuls, renvoie NaN
SELECT avgWeighted(x, w)
FROM VALUES('x Int8, w Int8', (0, 0), (1, 0), (10, 0))
┌─avgWeighted(x, w)─┐
│ nan │
└───────────────────┘
Une table vide renvoie NaN
CREATE TABLE test (t UInt8) ENGINE = Memory;
SELECT avgWeighted(t, t) FROM test
┌─avgWeighted(t, t)─┐
│ nan │
└───────────────────┘
Dernière modification le 29 juin 2026