Add matching values with SUM
Use SUM to total a numeric field across all records or a filtered subset.
Exam scope and assessment notes
This sequence follows Cambridge IGCSE Computer Science 0984, 2026–2028 syllabus Version 4, Topic 9. It covers single-table databases only and the specified SELECT, FROM, WHERE, ORDER BY, SUM, COUNT, AND and OR content. The official specimen also demonstrates NOT in a filter. Multi-table joins, GROUP BY, database implementation and the separate 2029–2031 syllabus are not mapped here. Practice is original, self-checked and does not award an official Cambridge grade. Full timed papers and human subject-teacher review remain outstanding. Cambridge states that 0984 has the same 2026–2028 subject content as 0478, with 9–1 grading. In June and November, Cambridge lists 0984 in Administrative zone 3 and for centres in Oman and the UAE. Confirm availability for your centre and exam series with Cambridge International. The separately published 2029–2031 syllabus changes to Python 3 only and removes pseudocode; this 2026–2028 route does not cover those changes.
Before you begin
- Be able to read a small table and compare values. Each lesson introduces the database and SQL terms it uses.
Work on paper. Try each question before revealing help, and explain why your method works.
Quick readiness check
Which field is more suitable for SUM: Price or ProductCode?
What you will learn
- Identify a numeric field to total
- Use SUM in a SELECT statement
- Combine SUM with a WHERE condition
SUM aggregates numeric values
SUM(FieldName) adds the values in a numeric field. It is suitable for quantities such as NumberInStock or Points, not for a text field such as Title.
The query returns one total for the selected set of records.
Filter the set before calculating the total
A WHERE condition limits which rows contribute to SUM. For example, sum stock only for records where Container = "Can".
Check the units and data type. A sum is meaningful only if the field values represent quantities that can be added.
Pause and explain
A query must total seats for Coding workshops only. Which parts are needed?
Worked example
A shop table SOFTDRINKS has NumberInStock and Container. Write a query to total stock for cans.
Show the worked solution
- Choose the numeric field NumberInStock.
- Apply SUM to the stock field.
- Filter Container to Can.
Answer SELECT SUM(NumberInStock) FROM SOFTDRINKS WHERE Container = "Can";
Try a topic test
Choose Easy, Normal or Difficult. Save your answers and open worked review after finishing.
Test this topic →From guided practice to a new situation
Write your answer and reasoning first. Use a hint only if you are stuck. The model solution is for self-checking; your written work is not automatically marked.
Stock values for Can records are 12, 8 and 5. What does SUM(NumberInStock) return for those rows?
Give me a hint
Add only the values from matching records.
Compare my reasoning
- Add 12 and 8 to get 20.
- Add 5 to get 25.
- The sum is 25.
25 units.
Look for these in your work
- Rows included
- Sum correct
Write a query to total Points for TEAM records where League = "East".
Give me a hint
Use SUM on the numeric field and a filter on League.
Compare my reasoning
- Select SUM(Points).
- Use TEAM as the table.
- Filter League = "East".
SELECT SUM(Points) FROM TEAM WHERE League = "East";
Look for these in your work
- Numeric aggregate
- Correct table
- Filter
A learner writes SUM(ShowNumber) to report total ticket sales. Explain the mismatch and name the field they should total instead.
Give me a hint
ShowNumber identifies a record; find the quantity representing sales.
Compare my reasoning
- An identifier is not an amount.
- The query should add ticket quantities or revenue.
- Use the numeric field matching the requested total, such as TicketsSold.
SUM should use a numeric quantity such as TicketsSold or Revenue, not the show identifier.
Look for these in your work
- Identifier distinction
- Relevant quantity
Common mistakes
- Summing text or identifier fields
- Forgetting the filter when only some records qualify
- Adding the number of records instead of their field values
What can you explain now?
Which function totals a numeric field?
Compare with the explanation
SUM
SUM adds the values in the named field.
After trying it yourself, choose your next review. This is your self-assessment.
Your review choice appears on Today. Sign in to sync it across devices.
Make it stick
When is SUM more appropriate than COUNT?
If you needed the solution, close it and solve the problem again from a blank page. A correct answer is stronger when you can explain the reason for each step.