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
Syntax
total(X)
Parameters
| Parameter | Description |
|---|---|
X |
A column or expression. |
Return value
A real number (0.0 when there are no values).
Examples
SELECT sum(price) AS with_sum, total(price) AS with_total
FROM products
WHERE price > 1000;
Output
with_sum | with_total NULL | 0
SELECT total(stock) AS units FROM products;
Output
units 495
In other languages
SUM()· PostgreSQL
Related
SUM()· Add up the non-NULL values in a group. Returns NULL when there are no values; total() returns 0.0 instead.- SQL Aggregate Functions · tutorial
- SQL GROUP BY · tutorial