Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

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.

Aggregates are allowed only in SELECT statements.

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 expression

  • DISTINCT - 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:

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 expressions

  • expression - specifies an expression that may be a column name, a result of another function, or a math operation

  • ORDER BY - orders rows by expression

  • SEPARATOR - overrides a string separator; by default, the separator character is the comma ','

The DISTINCT and ORDER BY expressions inside the GROUP_CONCAT function are only supported if you group the results by the primary or affinity key (i.e., use GROUP BY). Moreover, you have declare that your data is colocated by specifying the collocated=true property in the connection string or by calling SqlFieldsQuery.setCollocated(true) if you use the Java API.

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:

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 only

  • expression - 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

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

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

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

Example

Calculate the variance of players' age:

This page is: Copyright © 2026 MariaDB. All rights reserved.

Last updated

Was this helpful?