SQL SUM
Add up values.
Syntax
SUM(expression)
NULLs are skipped. Combine with CASE to count rows that meet a condition.
Example
Query (on the shop database used in the SQL course)
SELECT SUM(quantity) AS units, ROUND(SUM(quantity * unit_price), 2) AS revenue FROM order_items;
Result
| units | revenue |
|---|---|
| 234 | 23456.0 |
1 row
Related
Learn it step by step in the free lesson Summarising Data, with exercises that check your queries.