Print

Aggregate Functions

Aggregate functions are calculated for a bounded series of values, otherwise known as WINDOWS.

Aggregate functions can be used in SELECT and WHEN clauses of QUERIES only.

The following aggregate functions are available:

FunctionData TypesDescription
avgNUMBERAverage. sum divided by count
countNUMBER, STRINGQuantity of values in the window
count_distinctNUMBER, STRINGQuantity of unique values
firstNUMBER, STRINGThe oldest value in the window
lastNUMBER, STRINGThe most recent value in the window
maxNUMBER, STRINGThe highest number, or last alphabetically
medianNUMBERThe middle of values. If count is even, the middle point between two middle values
minNUMBER, STRINGThe lowest number, or first alphabetically
modeNUMBER, STRINGThe most commonly repeated value
previousNUMBERThe value before the most recent value
slopeNUMBERThe regresion line slope of values
stddevNUMBERStandard deviation
stddev_popNUMBERStandard Deviation of population
sumNUMBERThe sum of all values.
varianceNUMBERVariance
variance_popNUMBERVariance of population

Syntax

The aggregate function is prefixed by a window’s name or alias, and a period:

<window name>.<function>
<window alias>.<function>

Example

In the SELECT clause:

SELECT last_100_bids.AVG, last_100_bids.AVG
FROM last_100_bids
WHEN ...
OUTPUT (...);

In the SELECT clause with alias:

SELECT a.AVG, g.AVG
FROM last_100_bids_on_apple a, 
     last_100_bids_on_google g
WHEN ...
OUTPUT (...);

In the WHEN clause:

SELECT ...
FROM last_100_bids
WHEN last_100_bids.AVG > last_100_bids.AVG
OUTPUT (...);

In the WHEN clause with alias:

SELECT ...
FROM last_100_bids_on_apple a, 
     last_100_bids_on_google g
WHEN a.AVG > g.AVG
OUTPUT (...);
Table of Contents
Scroll to Top