Aggregate · Window
Aliases: any_value
A selected value can be NULL; it is not guaranteed to select a non-NULL row.
Syntax
A window function keeps each input row and adds a result for that row. PARTITION BY groups rows with matching values; without it, all input rows form one group. A frame from UNBOUNDED PRECEDING to UNBOUNDED FOLLOWING includes every row in the group.
Aggregate
Window over all rows in each group
- Use the full-group window shown above. Other frame boundaries, ordering options, and NULL-handling clauses are outside the forms covered on this page.
Arguments
Aggregate and full-group window
Returns
- Type: same SQL type as value
- NULL behavior: A selected value can be NULL; it is not guaranteed to select a non-NULL row.
- Empty input: Returns NULL on empty input.
Properties
Usage notes
- A NULL value can be selected, even when the group also contains non-NULL values.
- INTEGER and INT mean the same type; STRING means VARCHAR text. NULL can be used with a supported type. Cast NULL explicitly when its type would otherwise be unclear.
- Query tools may report a DECIMAL result as DOUBLE or a TIME result as INTEGER. The returned value still keeps its decimal precision and scale, or its time type. A reported type does not convert the value.
- Deterministic: The selected value can change if the input order changes.
- DISTINCT has no effect and does not make the function skip NULL values.
Examples
Choose a value within each group
One possible result is shown. Group a can return 7 or 9; group b can return 10 or 20. Do not rely on a particular choice.
Keep every row with a full-group window
The frame includes every row in each group. The query keeps all four input rows and adds a chosen value from that row’s group. This is one possible result; the chosen values can change.
A group containing only NULL
A group containing only NULL returns NULL. A mixed group can also return NULL; this function does not promise to choose a non-NULL value.
Limitations
- The result can be NULL even when other values are non-NULL. Adding DISTINCT does not make the function skip NULL values.
Last modified on October 15, 2026