SQLite 3 reference · 8 entries

SQLite Aggregate Functions

SQLite aggregate functions: count(), sum(), total(), avg(), min(), max(), group_concat() and string_agg(), with GROUP BY, FILTER and ORDER BY examples.

Aggregates turn many rows into one value, per group with GROUP BY. They ignore NULL values (except count(*)). Since 3.30, FILTER (WHERE …) limits the rows one aggregate sees, and since 3.44 an ORDER BY inside the call orders the values.

NameDescriptionSince
COUNT() Count rows: count(*) counts every row, count(X) counts rows where X isn't NULL, count(DISTINCT X) counts unique values.
SUM() Add up the non-NULL values in a group. Returns NULL when there are no values; total() returns 0.0 instead.
TOTAL() Add up the non-NULL values in a group like sum(), but always return a real number and 0.0 for no rows.
AVG() Return the average of the non-NULL values in a group, always as a real number. NULLs are ignored, not counted as 0.
MIN() With one argument, return the smallest value in a group. With two or more, return the smallest of the arguments.
MAX() With one argument, return the largest value in a group. With two or more, return the largest of the arguments.
GROUP_CONCAT() Join a group's non-NULL values into one string, separated by commas or a separator you give.
STRING_AGG() Join a group's values with a separator, the standard name also used by PostgreSQL and SQL Server. 3.44.0

Was this page helpful?