Aggregating Expressions
Aggregating expressions include one aggregating function and a field name.
An aggregating expression is an expression where any field name is contained in exactly one of the aggregating functions. For example, you could use the aggregating function max
in the statement group max(A) as Agg by B
.
GROUP BY and WINDOW Statements
GROUP BY
and WINDOW
statements must include an aggregating expression.
In a GROUP BY
or WINDOW
statement, the aggregating expression does not have to include a field name. For example:
GROUP 1.0 as price BY product_id;
is a valid statement that does not have a field name in the aggregating expression.
Additional Examples
A few additional examples of statements with aggregating expressions:
GROUP first(price) + 1.0 as first_price BY product_id;
GROUP array(max(us_price), max(eu_price)) as prices BY product_id;
WINDOW max(price_1) + max(price_2) as max_price BY product_id;
and
WINDOW array(max(price_1), max(price_2)) as prices BY product_id;
are all valid aggregations.
Note: Nested aggregating functions are not allowed. A sequence of aggregations must be provided instead. For example, these statements:
GROUP first(1.0 + max(price)) as max_price BY product_id;
and
WINDOW mean((price - mean(price)) * (price - mean(price))) as var_price BY product_id
are not allowed.
Updated over 2 years ago