SQLite 3 reference · Aggregate Functions

SQLite TOTAL() Function

Add up the non-NULL values in a group like sum(), but always return a real number and 0.0 for no rows.

SQLite 3

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

total(X)

Parameters

ParameterDescription
X A column or expression.

Return value

A real number (0.0 when there are no values).

Examples

No matching rowsTry it yourself
SELECT sum(price) AS with_sum, total(price) AS with_total
FROM products
WHERE price > 1000;

Output

with_sum | with_total
NULL | 0
Always a real numberTry it yourself
SELECT total(stock) AS units FROM products;

Output

units
495

In other languages

Was this page helpful?