ANY_VALUE() OVER ...
All functions > WINDOW FUNCTION > ANY_VALUE() OVER ...
Returns an arbitrary non-null value from the window frame, if one exists.
Syntax
ANY_VALUE(expr) [FILTER (WHERE condition) | WITHIN (WHERE condition)] OVER ([PARTITION BY expr [, ...]] [ORDER BY sort_item [, ...]] [ROWS|RANGE|GROUPS frame])
Notes
- Returns any non-null value from the window frame
- Useful when you need a representative value but don't care which one
- Returns same type as input expression
- Non-deterministic: result may vary between executions
See also
Examples
FeatureQL
SELECT
-- Any non-null value in the frame (here, first in id order; v permuted so output is not v)
f1 := ZIP(ARRAY(1, 2, 3, 4) AS id, ARRAY(30, 10, 20, 5) AS v).TRANSFORM(
SELECT ANY_VALUE(v) OVER (ORDER BY id ASC)
).UNWRAP(),
-- Any value counting only rows where v > 15 (10 and 5 excluded from the frame)
f2 := ZIP(ARRAY(1, 2, 3, 4) AS id, ARRAY(30, 10, 20, 5) AS v).TRANSFORM(
SELECT ANY_VALUE(v) FILTER (WHERE v > 15) OVER (ORDER BY id ASC)
).UNWRAP()
;Result
| f1 ARRAY | f2 ARRAY |
|---|---|
| [30, 30, 30, 30] | [30, 30, 30, 30] |