ANY_VALUE() GROUP BY ...
All functions > GROUP BY > ANY_VALUE() GROUP BY ...
Returns an arbitrary value from the group.
Syntax
Diagram(
Sequence(
Terminal("ANY_VALUE"),
Terminal("("),
NonTerminal("expr"),
Terminal(")"),
Choice(0, Skip(),
Sequence(
Terminal("FILTER"),
Terminal("("),
Terminal("WHERE"),
NonTerminal("condition"),
Terminal(")")
)
),
Choice(0, Skip(),
Sequence(
Terminal("GROUP BY"),
OneOrMore(NonTerminal("feature"), Terminal(","))
)
)
)
)| Parameter | Type | Required | Description |
|---|---|---|---|
expr | T | Yes | The expression to evaluate |
condition | BOOLEAN | No | The condition to filter the values before aggregation |
feature | FEATURE | No | The features to group by (many features are supported) |
Notes
- Result is non-deterministic: may return different values across runs
- Useful when you need any value from a group and don't care which one
- More efficient than MIN() or MAX() when exact value doesn't matter
- 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
Examples
FeatureQL
SELECT
f1 := ZIP(ARRAY[1, 1, 1] AS value).TRANSFORM(SELECT ANY_VALUE(value)).UNWRAP_ONE() -- Any value from the group
;Result
| f1 BIGINT |
|---|
| 1 |