Aggregate Functions
Reference of the SQL aggregate functions supported by GridGain — AVG, BIT_AND, BIT_OR, COUNT, GROUP_CONCAT, MAX, MIN, SUM, and statistical aggregates.
AVG
Description
Computes and returns the average (mean) value of the specified parameter for the selected table rows. If no rows are selected, the result is NULL. The returned value is of the same data type as the specified parameter.
AVG ([DISTINCT] expression)Parameters
expression- any valid numeric expressionDISTINCT- an optional keyword; if present, the function averages unique values only
Example
Calculate the average players' age:
SELECT AVG(age) "AverageAge" FROM Players;BIT_AND
Description
Returns the bitwise AND of all non-null values. If no rows are selected, the result is NULL. A logical AND operation is performed on each pair of corresponding bits of two binary expressions of equal length. In each pair, it returns 1 if the first bit is 1 AND the second bit is 1. Else, it returns 0.
Parameters
expression - the input data
BIT_OR
Description
Return the bitwise OR of all non-null values. If no rows are selected, the result is NULL. A logical OR operation is performed on each pair of corresponding bits of two binary expressions of equal length. In each pair, the result is 1 if the first bit is 1 OR the second bit is 1 OR both bits are 1. Otherwise, the result is 0.
Parameters
expression - the input data
COUNT
Description
Counts all entries or all non-null values. Returns a long. If no entries are selected, the result is 0.
Example
Calculate the number of players in each city:
FIRSTVALUE
Description
Returns the value of expression1 associated with the smallest value of expression2 for each group defined by the group by expression in the query.
This function can only be used with colocated data; you have to use the colocated flag when executing the query.
The collocated hint can be set as follows:
SqlFieldsQuery.collocated = trueif you use GridGain SQL API to execute queries
Example
Return the youngest person for each Company from the Person table and group them by Company ID:
GROUP_CONCAT
Description
Concatenates strings with a separator. The default separator is ',' (without whitespace). Returns a string. If no entries are selected, the result is NULL.
Expression can be a concatenation of columns and strings with the || operator; for example: column1 || "=" || column2.
Parameters
DISTINCT- filters the result set for unique sets of expressionsexpression- specifies an expression that may be a column name, a result of another function, or a math operationORDER BY- orders rows by expressionSEPARATOR- overrides a string separator; by default, the separator character is the comma ','
Example
Group all players' names in one row:
LASTVALUE
Description
Returns the value of expression1 associated with the largest value of expression2 for each group defined by the group by expression.
This function can only be used with colocated data and you have to use the collocated flag when executing the query.
The colocated hint can be set as follows:
SqlFieldsQuery.collocated=trueif you use GridGain SQL API to execute queries
Example
Return the oldest person for each Company from the Person table and group them by Company ID:
MAX
Description
Returns the highest value for the specified parameter. If no entries are selected, the result is NULL. The returned value is of the same data type as the parameter.
Parameters
expression - may be a column name, a result of another function, or a math operation
Example
Return the height of the tallest player:
MIN
Description
Returns the lowest value for the specified parameter. If no entries are selected, the result is NULL. The returned value is of the same data type as the parameter.
Parameters
expression - may be a column name, a result of another function, or a math operation
Example
Return the age of the youngest player:
SUM
Description
Returns the sum of all values of a parameter. If no entries are selected, the result is NULL. The data type of the returned value depends on the parameter data type.
Parameters
DISTINCT- sum up unique values onlyexpression- may be a column name, a result of another function, or a math operation
Example
Get the total number of goals scored by all players:
STDDEV_POP
Description
Returns the standard deviation value for a population (double). If no entries are selected, the result is NULL.
Parameters
DISTINCT- calculate for unique values onlyexpression- may be a column name, etc.; see Microsoft language manual
Example
Calculate the standard deviation for players' age:
STDDEV_SAMP
Description
Calculates the standard deviation for a sample (double). If no entries are selected, the result is NULL.
Parameters
DISTINCT- calculate for unique values onlyexpression- may be a column name, etc.; see Microsoft language manual
Example
Calculate the sample standard deviation for players' age:
VAR_POP
Description
Calculates the variance (square of the standard deviation) for a population. It returns a double. If no entries are selected, the result is NULL.
Parameters
DISTINCT- calculate for unique values onlyexpression- may be a column name, etc.; see Microsoft language manual
Example
Calculate the variance of players' age:
VAR_SAMP
Description
Calculates the variance (square of the standard deviation) for a sample. It returns a double. If no entries are selected, the result is NULL.
Parameters
DISTINCT- calculate for unique values onlyexpression- may be a column name, etc.; see Microsoft language manual
Example
Calculate the variance of players' age:
This page is: Copyright © 2026 MariaDB. All rights reserved.
Last updated
Was this helpful?

