ANY_VALUE() GROUP BY ...

All functions > GROUP BY > ANY_VALUE() GROUP BY ...

Returns a value of the group: the minimum in value order.

Syntax

ANY_VALUE(expr)
 [ FILTER (WHERE condition) ]
  [ GROUP BY feature [, feature ...] ]

Notes

  • Deterministic: the result is MIN() of the group, the same on every run and every backend
  • When the GROUP BY keys determine the value (a lookup of a key, a column of the key's entity), the native ANY_VALUE is emitted: it returns that value without comparing
  • EXPLAIN (FIELDS (OPTIMIZATIONS)) records the choice as any_value_native
  • Returns NULL if all values in the group are NULL
  • Can be used with WHERE clause to filter before aggregation
  • Can be used with GROUP BY clause for grouped aggregation

See also

Examples

FeatureQL
-- The minimum of the group
RETURN
    f1 := ZIP(ARRAY(3, 1, 2) AS value).TRANSFORM(RETURN ANY_VALUE(value)).UNWRAP_ONE()
;
Result
f1 BIGINT
1