Aggregation
Aggregates compute count, sum, min, max, or average.
What it is
Aggregates compute count, sum, min, max, or average.
When to use it
Build reports within one currency and defined status.
Syntax
COUNT(*) | SUM(amount_cents) | MIN(amount_cents) | MAX(amount_cents)Example
SELECT currency, COUNT(*) AS count, SUM(amount_cents) AS settled_cents
FROM transactions WHERE status = 'settled'
GROUP BY currency;Common mistakes
Do not sum different currencies; SUM over no rows returns NULL; AVG may return a noninteger.