SUM adds up a whole column
Starting table: shifts
| id | tip |
|---|---|
| 1 | 30 |
| 2 | 42.5 |
| 3 | 25 |
| 4 | 45 |
SUM takes one column of numbers and returns the total. Like COUNT, it turns many rows into one answer, so a single number appears in your results rather than a list of rows.
A tiny example
In plain English: Tell me the total of all the tips from every shift.
SELECT SUM(tip)
FROM shifts;Query result
| SUM(tip) |
|---|
| 142.5 |
Every tip from every shift added together comes to 142.5.
Common questions
- What does SUM do with NULL values?
- It skips them. SUM adds up only the rows where the column has a value, so a NULL never changes the total.
- How do I get a total per group instead of one grand total?
- Add GROUP BY, such as SELECT city, SUM(total) FROM orders GROUP BY city. Each city gets its own row with its own total.
Related SQL lessons
Practice SUM step by step
The Foundations Track has beginner puzzles built around this idea. Tap tiles, see real results. No terminal, no setup.
practice this in the courseReady for a break?
A fresh, bite-sized SQL puzzle waits every morning. Tap tiles, see real results. No terminal, no setup, no timers.
Try today's free SQL puzzle