TOPN_WEIGHTED

description

Syntax

ARRAY<T> topn_weighted(expr, BigInt weight, INT top_num[, INT space_expand_rate])

The topn_weighted function is calculated using the Space-Saving algorithm, and the sum of the weights in expr is the result of the top n numbers, which is an approximate value

The space_expand_rate parameter is optional and is used to set the number of counters used in the Space-Saving algorithm

1. counter numbers = top_num * space_expand_rate

The higher value of space_expand_rate, the more accurate result will be. The default value is 50

example

1. mysql> select topn_weighted(k5,k1,3) from baseall;
2. +------------------------------+
3. | topn_weighted(`k5`, `k1`, 3) |
4. +------------------------------+
5. | [0, 243.325, 100.001]        |
6. +------------------------------+
7. 1 row in set (0.02 sec)

9. mysql> select topn_weighted(k5,k1,3,100) from baseall;
10. +-----------------------------------+
11. | topn_weighted(`k5`, `k1`, 3, 100) |
12. +-----------------------------------+
13. | [0, 243.325, 100.001]             |
14. +-----------------------------------+
15. 1 row in set (0.02 sec)

keywords

TOPN, TOPN_WEIGHTED