Newer Version Available
Aggregate Functions
Using an aggregate function on an empty set returns null. For example, if you use an aggregate function with a nonmatching column of an outer cogrouping, you might have an empty set.
This table lists the aggregate functions that are supported:
| Aggregate Function | Description |
|---|---|
| avg() or average() | Returns the average value of a numeric field. For example, to calculate the average
number of
miles:
|
| count() | Returns the number of rows that match the query criteria. For example, to calculate
the number of
carriers:
The
count() function operates on streams that were inputs
to the group or cogroup statements. It doesn’t operate on the newly grouped stream or on an
ungrouped stream.
|
| first() | Returns the value for the first tuple. To work as expected, you must be aware of the
sort order or know that the values of that measure are the same for all tuples in the
set. For example, you can use these statements to compute the distance between each combination of origin and destination: |
| last() | Returns the value for the last tuple. For example, to compute the distance between each combination of origin and destination: |
| max() | Returns the maximum value of a field. This function takes only a measure as an argument. It can’t take a dimension. |
| median() | Accepts a grouped expression of numeric type and returns the middle number (by sorted
order, ignoring null values). If there is no one middle number (in other words, the count of
non-null values is even), then median returns the average of the two numbers closest to the
middle. The expression can be any identifier, such as ‘xInt’ or ‘price’, but cannot be a complex expression, such as price/100 or ceil(distance), or a literal, such as 2.5. |
| min() | Returns the minimum value of a field. This function takes only a measure as an argument. It can’t take a dimension. |
| sum() | Returns the sum of a numeric
field. |
| unique() | Returns the count of unique values. For example, to find how many origins and destinations a carrier flies from: |