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

[
   {
      "user":"A01",
      "level":1,
      "score":25
   },
   {
      "user":"A01",
      "level":2,
      "score":48
   },
   {
      "user":"A01",
      "level":2,
      "score":81
   },
   {
      "user":"B02",
      "level":1,
      "score":23
   },
   {
      "user":"B02",
      "level":1,
      "score":29
   }
]

Query

SELECT
   data.level AS level:BIGINT,
   MIN(data.score) AS min_data_score:BIGINT,
   MIN_BY(data.user, data.score) AS min_by_data_user__data_score:STRING 
FROM
   "MAX_SAMPLE_DATA - json" 
GROUP BY
   data.level

Results

{
   "min_data_score":48,
   "level":2,
   "min_by_data_userdata_score":"A01"
}{
   "min_data_score":23,
   "level":1,
   "min_by_data_userdata_score":"B02"
}

MAX_BY MIN MIN_EACH MIN_TIME_SERIES

Dialog

Last updated