VeloDB Cloud
SQL Manual
Functions
aggregate-functions
TOPN_ARRAY

TOPN_ARRAY

Description

Syntax:

ARRAY<T> topn_array(expr, INT top_num[, INT space_expand_rate])

This function uses the Space-Saving algorithm to calculate the top_num most frequent items in expr. It returns the frequent items and their occurrence times, which is an approximation.

The space_expand_rate parameter is optional. It determines the number of counters used in the Space-Saving algorithm.

counter numbers = top_num * space_expand_rate

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

Example

mysql> select topn_array(k3,3) from baseall;
+--------------------------+
| topn_array(`k3`, 3)      |
+--------------------------+
| [3021, 2147483647, 5014] |
+--------------------------+
1 row in set (0.02 sec)

mysql> select topn_array(k3,3,100) from baseall;
+--------------------------+
| topn_array(`k3`, 3, 100) |
+--------------------------+
| [3021, 2147483647, 5014] |
+--------------------------+
1 row in set (0.02 sec)

Keywords

TOPN, TOPN_ARRAY