Passer au contenu principal

avgWeighted

Introduite dans : v20.1.0 Calcule la moyenne arithmétique pondérée. Syntaxe
avgWeighted(x, weight)
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
Query
SELECT avgWeighted(x, w)
FROM VALUES('x Int8, w Int8', (4, 1), (1, 0), (10, 2))
Response
┌─avgWeighted(x, w)─┐
│                 8 │
└───────────────────┘
Poids mixtes entiers et flottants
Query
SELECT avgWeighted(x, w)
FROM VALUES('x Int8, w Float64', (4, 1), (1, 0), (10, 2))
Response
┌─avgWeighted(x, w)─┐
│                 8 │
└───────────────────┘
Si tous les poids sont nuls, renvoie NaN
Query
SELECT avgWeighted(x, w)
FROM VALUES('x Int8, w Int8', (0, 0), (1, 0), (10, 0))
Response
┌─avgWeighted(x, w)─┐
│               nan │
└───────────────────┘
Une table vide renvoie NaN
Query
CREATE TABLE test (t UInt8) ENGINE = Memory;
SELECT avgWeighted(t, t) FROM test
Response
┌─avgWeighted(t, t)─┐
│               nan │
└───────────────────┘
Dernière modification le 29 juin 2026