Topic 9 · Databases · 9.6

SUM Explained Simply

SUM adds together the numeric values in a database field and returns one total.

Invitation

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.

SUM totals a numeric field.
How SUM works
81 · 65 · 90 · 72
SUM(Score)
308
Big Idea

Read SUM as one simple sentence

SQL QueryPlain English
SELECT SUM(Score)
FROM Students;
SELECT SUM(Score)Add together every value in the Score field.
FROM StudentsUse the Students table.
Plain English: “Add together every score in the Students table.”
How It Works

Keep the same three-step pattern

The learning map does not change. Only the query changes.

1. DATABASEStudents table
2. QUERYSELECT SUM(Score) FROM Students
3. OUTPUTOne total: 308
Database → Query → One Total.
Worked Example

Follow the database, query and output

1. Database

StudentIDNameAgeScore
101Alice1581
102Ben1665
103Chen1590
104Dia1672

2. SQL Query

SQLTotal
SELECT SUM(Score)
FROM Students;

3. Output

308
Follow the values: 81 + 65 + 90 + 72 = 308.
Using WHERE

SUM can total only the matching records

SQL QueryMeaning
SELECT SUM(Score)
FROM Students
WHERE Age = 15;

Matching records

NameAgeScore
Alice1581
Chen1590

Output

171

Only the matching scores are added: 81 + 90.

WHERE filters first. SUM totals second.
Exam Tip

SUM returns one total, not the original records

1Find the numeric field inside SUM.
2Apply any WHERE condition.
3Add the remaining values.
Exam rule: SUM is used with numeric fields and returns a single total.
Common Mistake

Do not list the values when the query asks for their total

✗ Incorrect output

81 65 90 72

These are the original values, not their total.

✓ Correct output

308

SUM returns one total.

Remember: The field inside SUM must contain numbers that can be added.
Summary

One function, one clear job

SUMAdds numeric values.
WHERECan filter values first.
OUTPUTOne total.
Final rule: SUM adds together the values in a numeric field and returns one answer.