SQL Sum()
SUM adds the non-NULL values in its input. Before writing a sales total, decide which statuses count as sales and whether the amount is an order total, a payment, or a refund.
Understand the idea
The sample contains paid, pending, and cancelled orders. Only paid orders belong in this simple revenue query. Amounts are stored as integer cents to avoid representing ordinary currency amounts with approximate binary floating-point values. In production, account for currencies, taxes, refunds, and the exact reporting definition.
Where to try it
Run this example in the SQL playground. The lesson link loads the shop tables and sample rows before this query. Select Run when you are ready. Every run starts fresh, so your changes do not affect the website or a previous run.
SQLite sample data · MySQL / MariaDB sample data · See the sample tables
A worked example
SELECT SUM(total_cents) AS paid_cents
FROM orders
WHERE status = 'paid';
Read the result
The paid total is 3650 cents: 2300 plus 1350. Including pending and cancelled orders would report a different number and would not match the question.
Try one change
Calculate the pending total separately. Then filter to a status that does not exist and inspect the NULL result.