Upsolver
Search…
MAX_BY
The value correlating to the maximum sort in the time window.

‌Syntax

MAX_BY(VALUE, SORT)

Arguments

VALUE: An expression of any type. SORT: An integer type that can be ordered. ‌

Returns

The result type matches the VALUE type. If the maximum value is not unique, the first VALUE in the set will be returned.

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":"B02",
19
"level":1,
20
"score":23
21
},
22
{
23
"user":"B02",
24
"level":1,
25
"score":29
26
}
27
]
Copied!

Query

1
SELECT
2
MAX_BY(data.user, data.score) AS max_by_data_user__data_score:STRING,
3
MAX(data.score) AS max_data_score:BIGINT,
4
data.level AS level:BIGINT
5
FROM
6
"MAX_SAMPLE_DATA - json"
7
GROUP BY
8
data.level
Copied!

Results

1
{
2
"level":2,
3
"max_data_score":81,
4
"max_by_data_userdata_score":"A01"
5
}{
6
"level":1,
7
"max_data_score":29,
8
"max_by_data_userdata_score":"B02"
9
}
Copied!

Dialog

Last modified 8mo ago