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

Syntax

MIN_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 minimum per 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
data.level AS level:BIGINT,
3
MIN(data.score) AS min_data_score:BIGINT,
4
MIN_BY(data.user, data.score) AS min_by_data_user__data_score:STRING
5
FROM
6
"MAX_SAMPLE_DATA - json"
7
GROUP BY
8
data.level
Copied!

Results

1
{
2
"min_data_score":48,
3
"level":2,
4
"min_by_data_userdata_score":"A01"
5
}{
6
"min_data_score":23,
7
"level":1,
8
"min_by_data_userdata_score":"B02"
9
}
Copied!

Dialog

Last modified 8mo ago