Description
PERCENTILE_APPROX_WEIGHTED(expr, w ,DOUBLE p [, DOUBLE compression])
该函数和 PERCENTILE_APPROX 类似,唯一的区别是多了一个参数 w,用来表示 expr 出现的次数。 注意参数 W 的取值需要大于0,如果计算过程中某一行的取值小于等于0时,则会跳过当前行。
Example
$ mysql >select * from quantile_weighted_table order by k;
+------+------+
| k | w |
+------+------+
| 1 | 2 |
| 3 | 1 |
| 5 | 2 |
+------+------+
$ mysql >select percentile_approx_weighted(k,w,0.55) from quantile_weighted_table;
+----------------------------------------------------------------------------------------+
| percentile_approx_weighted(cast(k as DOUBLE), cast(w as DOUBLE), cast(0.55 as DOUBLE)) |
+----------------------------------------------------------------------------------------+
| 3.3333332538604736 |
+----------------------------------------------------------------------------------------+
Keywords
RCENTILE_APPROX, PERCENTILE, APPROX, PERCENTILE_APPROX_WEIGHTED