What if you need one total from a whole column?
In Topic 8, you learned how a running total grows one value at a time.
In SQL, SUM performs that total for you. It adds all the numeric values in the chosen field and returns one answer.
In Cambridge IGCSE Computer Science (0478 and 0984), the SQL SUM function adds together all numeric values in a specified field and returns a single total. When paired with a WHERE clause, SQL filters matching rows first before calculating the final sum.
Practise totalling scores in the Students table with and without WHERE conditions so you always return one combined answer in Topic 9.6 exam questions.
In Topic 8, you learned how a running total grows one value at a time.
In SQL, SUM performs that total for you. It adds all the numeric values in the chosen field and returns one answer.
SELECT SUM(Score) FROM Students;
The learning map does not change. Only the query changes.
| StudentID | Name | Age | Score |
|---|---|---|---|
| 101 | Alice | 15 | 81 |
| 102 | Ben | 16 | 65 |
| 103 | Chen | 15 | 90 |
| 104 | Dia | 16 | 72 |
SELECT SUM(Score) FROM Students;
SELECT SUM(Score) FROM Students WHERE Age = 15;
| Name | Age | Score |
|---|---|---|
| Alice | 15 | 81 |
| Chen | 15 | 90 |
Only the matching scores are added: 81 + 90.
These are the original values, not their total.
SUM returns one total.