SLOPDB / DOCUMENTATION / AGGREGATE FUNCTIONS

Aggregate functions

Function inventory verified against the supplied SlopDB source checkout e5e2eb2. Entries document implemented behavior, including compatibility placeholders and restrictions.

← Search all SQL functions · 7 documented names/forms in this family.

Grouped aggregates consume rows and return one result per group, or one result for an ungrouped aggregate query. They ignore NULL expression values; COUNT(*) counts rows instead. Aggregates can appear in SELECT, HAVING, and ORDER BY, but cannot be nested directly or placed in WHERE/JOIN conditions.

DISTINCT and empty inputs

DISTINCT removes duplicate non-NULL values before aggregation, normally for one expression. Empty input returns zero for COUNT and 0.0 for TOTAL; the other aggregates return NULL. SUM/AVG/TOTAL require numeric input. MIN/MAX use the active comparison rules. The engine supports bounded execution and relevant operator spills; see query memory.

Window forms

COUNT, SUM, AVG, MIN, and MAX also accept OVER and operate on the current window frame without collapsing rows. TOTAL and GROUP_CONCAT are not supported window functions. DISTINCT window aggregates and FILTER are unsupported. See window frames and execution.

Grouped aggregates

AVG([DISTINCT] expression)

Returns numeric

Averages non-NULL numeric values. Empty input returns NULL. Exact DECIMAL/unsigned inputs follow the engine’s bounded-scale decimal average path.

SELECT AVG(v) FROM (SELECT 1 AS v UNION ALL SELECT 2 UNION ALL SELECT NULL) AS sample;
Source: sql/aggregate_execution.go · e5e2eb2

COUNT(*) or COUNT([DISTINCT] expression)

Returns INTEGER

Counts all rows with star, or non-NULL expression values. Empty input returns zero.

SELECT COUNT(v) FROM (SELECT 1 AS v UNION ALL SELECT 2 UNION ALL SELECT NULL) AS sample;
Source: sql/aggregate_execution.go · e5e2eb2

GROUP_CONCAT(expression [, separator]) or GROUP_CONCAT(DISTINCT expression)

Returns TEXT

Concatenates non-NULL expression values. Separator defaults to comma. Empty input returns NULL; without explicit ordering the order is not guaranteed.

MySQL also supports multiple expressions, ORDER BY, and SEPARATOR syntax. DISTINCT is normally one expression; see the MySQL guide for that extended form.

SELECT GROUP_CONCAT(v) FROM (SELECT 1 AS v UNION ALL SELECT 2 UNION ALL SELECT NULL) AS sample;
Source: sql/aggregate_execution.go · e5e2eb2

MAX([DISTINCT] expression)

Returns selected value

Returns the least/greatest non-NULL value under active comparison rules; empty input returns NULL. Two or more scalar arguments select the scalar form.

SELECT MAX(v) FROM (SELECT 1 AS v UNION ALL SELECT 2 UNION ALL SELECT NULL) AS sample;
Source: sql/aggregate_execution.go · e5e2eb2

MIN([DISTINCT] expression)

Returns selected value

Returns the least/greatest non-NULL value under active comparison rules; empty input returns NULL. Two or more scalar arguments select the scalar form.

SELECT MIN(v) FROM (SELECT 1 AS v UNION ALL SELECT 2 UNION ALL SELECT NULL) AS sample;
Source: sql/aggregate_execution.go · e5e2eb2

SUM([DISTINCT] expression)

Returns numeric

Adds non-NULL numeric values. Empty input returns NULL. Integer sums are exact and fail on signed overflow; exact DECIMAL/unsigned inputs use exact accumulation.

SELECT SUM(v) FROM (SELECT 1 AS v UNION ALL SELECT 2 UNION ALL SELECT NULL) AS sample;
Source: sql/aggregate_execution.go · e5e2eb2

TOTAL([DISTINCT] expression)

Returns REAL

Adds numeric values as REAL; empty input returns 0.0. Nonnumeric values and nonfinite totals fail.

SELECT TOTAL(v) FROM (SELECT 1 AS v UNION ALL SELECT 2 UNION ALL SELECT NULL) AS sample;
Source: sql/aggregate_execution.go · e5e2eb2
Function reference checked against engine source · e5e2eb2Edit the function reference ↗