Skip to main content

TOTAL

Returns the sum of all non NULL values in a column or grouping of columns.

See also:
[SELECT] [SUM]


Syntax​

SELECT TOTAL(columnExpression) FROM <multipartIdentifier>
[ GROUP BY groupByColumn ];

Arguments​

columnExpression
A column or expression.

If all the values in the columnExpression are NULL then TOTAL returns 0.0.

groupByColumn
A column or columns used to perform summary or aggregate operations against. The GROUP BY clause returns one row for each column grouping.

Return Value(s)​

Returns a floating point value representing the sum of the columnExpression.


Examples​

Return the sum of a column expression over an entire resource​

SELECT total(json_array_length(disks)) as total_disks
FROM google.compute.instances
WHERE project = 'stackql-demo'
AND zone = 'australia-southeast1-a';

Return the sum of a column expression grouped by another column expression​

SELECT tags, total(json_array_length(disks)) as total_disks
FROM google.compute.instances
WHERE project = 'stackql-demo'
AND zone = 'australia-southeast1-a'
GROUP BY json_extract(tags, '$.instanceType');

For more information, see https://www.sqlite.org/lang_aggfunc.html#sumunc.