Aggregates
Count and Sum
Whole-Table Totals
Aggregate functions collapse many rows into one summary row.
Program
Play the query to count orders and sum revenue.
count_sum.sql
CREATE TABLE orders (id INTEGER, total INTEGER);
INSERT INTO orders VALUES (1, 12), (2, 30), (3, 8);
SELECT COUNT(*) AS orders, SUM(total) AS revenue FROM orders;
COUNT
`COUNT(*)` counts rows.
SUM
`SUM(total)` adds a numeric column.
alias
`AS revenue` names the output column.