SUM
An aggregate that adds up the non-NULL values in a group.
In more detail
Summing integer cents gives an exact total. SUM over no rows, or over only NULLs, returns NULL rather than zero; SQLite's total() or coalesce(SUM(x), 0) gives zero instead.
Example
SUM(quantity * unit_price_cents)Related terms
- aggregate function — A function that turns many input rows into one value, such as COUNT, SUM, AVG, MIN or MAX.
- money in cents — The practice of storing money as a whole number of the smallest unit, such as cents, so sums are exact.
- AVG — An aggregate that returns the arithmetic mean of the non-NULL values in a group.
Taught in
- Cross Joins And Cartesian Bugs — PostgreSQL, Indexing & Relational Data Modeling
- Aggregate Functions — PostgreSQL, Indexing & Relational Data Modeling
- The GROUP BY Clause — PostgreSQL, Indexing & Relational Data Modeling