AVG_WEIGHTED

Description

Syntax

double avg_weighted(x, weight)

Calculate the weighted arithmetic mean, which is the sum of the products of all corresponding values and weights, divided the total weight sum. If the sum of all weights equals 0, NaN will be returned.

example

  1. mysql> select avg_weighted(k2,k1) from baseall;
  2. +--------------------------+
  3. | avg_weighted(`k2`, `k1`) |
  4. +--------------------------+
  5. | 495.675 |
  6. +--------------------------+
  7. 1 row in set (0.02 sec)

keywords

AVG_WEIGHTED