Upsolver
Search…
COUNT_EACH
The number of items grouped by the given key.

Syntax

COUNT_EACH([MAX VALUES, ]GROUP)

Arguments

MAX VALUES: The maximum number of entries that can be counted (default: 2,147,483,647). When MAX VALUES is omitted, the limit is simply set to the default value. GROUP: The field you would like counted.

Returns

An integer

Notes

"EACH" Aggregate Functions, such as this one, only work when emitting hierarchical data.

Example

Data

1
[
2
{
3
"user":"A01",
4
"level":1,
5
"score":25
6
},
7
{
8
"user":"A01",
9
"level":2,
10
"score":48
11
},
12
{
13
"user":"A01",
14
"level":2,
15
"score":81
16
},
17
{
18
"user":"A01",
19
"level":2,
20
"score":81
21
},
22
{
23
"user":"B02",
24
"level":1,
25
"score":23
26
},
27
{
28
"user":"B02",
29
"level":1,
30
"score":29
31
}
32
]
Copied!

Query

Display hierarchical results of each value, with the matching count of the value. This resembles a count field + group by query, except that the results are formatted as a single hierarchy.
1
SELECT
2
data.User AS user:STRING,
3
data.Level AS level:BIGINT,
4
COUNT_EACH(data.User) AS count_each_data_user
5
FROM
6
"MAX_SAMPLE_DATA_2"
7
GROUP BY
8
data.User,
9
data.Level
Copied!

Results

1
{
2
"level":2,
3
"user":"A01",
4
"count_each_score":[
5
{
6
"value":1,
7
"key":48
8
},
9
{
10
"value":2,
11
"key":81
12
}
13
]
14
}{
15
"level":1,
16
"user":"B02",
17
"count_each_score":[
18
{
19
"value":1,
20
"key":23
21
},
22
{
23
"value":1,
24
"key":29
25
}
26
]
27
}{
28
"level":1,
29
"user":"A01",
30
"count_each_score":[
31
{
32
"value":1,
33
"key":25
34
}
35
]
36
}
Copied!

Dialog