User GuidesAPI ReferenceRelease Notes
Doc HomeHelp CenterLog In
User Guides

Aggregate Expressions

Overview

An aggregation 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 aggregate expression.

In a group by or window statement, the aggregation expression does not have to include a field name. For example

GROUP 1.0 as price BY product_id;

is a valid aggregation statement that does not have a field name in the aggregation expression.

Additional Examples

A few additional examples of aggregation statements:

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.

Remember, nested aggregation functions are not allowed. A sequence of aggregations must be provided instead. For example, the 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.