← IGCSE Computer Science Paper 2

SQL SUM function

Adds up all the values in a numeric field and returns one total, e.g. SELECT SUM(Score) FROM Results; gives one row. It only works on numbers.

Understanding SQL SUM function in IGCSE Computer Science Paper 2

What it does: Quantity is an integer field, so SUM adds all its values and returns one row holding the total. Mark holds numbers, so it can be added. SUM cannot be used on text fields such as Surname. SUM combines all the values into a single total, so the output is one row. The field name must go inside brackets after SUM: SUM(Price). 2 + 0 + 3 + 1 = 6. The answer 4 is what COUNT would give, as it counts the records. SUM needs numbers to add, so it works on integer and real fields only.

Common mistakes: The keyword is misspelled. It should be FROM Results, because FROM names the table that SUM reads. SUM needs brackets around the field name. It should be SUM(Score).

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 525–538) and word search (Modules 500–538).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Which SQL statement adds up every value in the Score field of the Results table?
SELECT SUM(Score) FROM Results;SELECT COUNT(Score) FROM Results;
Matches
SELECT SUM(Surname) FROM Students;
↓
SUM cannot be used on a text field. Surname is not numeric, so it cannot be added up.
Applying
Meanings
Term
SUM(field)
Meaning
Adds up all the values in a numeric field and returns one total, e.g. SELECT SUM(Score) FROM Results; gives one row. It only works on numbers.
Practice
SELECT SUM(mark)
Testing
Gaps
SELECT (Score) FROM Results;
Check Answer
Spots
1SELECT SUM(Score)
2FORM Results

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Dumbo Octopus' badge — Module Maker, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Which SQL statement adds up every value in the Score field of the Results table?
A. SELECT SUM(Score) FROM Results; ✓
B. SELECT COUNT(Score) FROM Results;
SUM adds the values together to give a total. COUNT only counts how many records there are.
2. How many rows of output does SELECT SUM(Score) FROM Results; give?
A. One row for each record in Results
B. One row containing the total ✓
SUM combines all the values into a single total, so the output is one row.
3. Which field is suitable for use inside SUM()?
A. Price, a real (floating point) field ✓
B. Surname, a text field
SUM only works on numeric fields. You cannot add up text values.
4. Which statement is written correctly?
A. SELECT SUM(Price) FROM Orders; ✓
B. SELECT SUM Price FROM Orders;
The field name must go inside brackets after SUM: SUM(Price).
5. A table has an integer field Goals with the values 2, 0, 3 and 1. What does SELECT SUM(Goals) FROM Matches; output?
A. 4
B. 6 ✓
2 + 0 + 3 + 1 = 6. The answer 4 is what COUNT would give, as it counts the records.

Match the Pairs

SELECT SUM(Score) FROM Results; → Adds up every value in the Score field and returns one total
SELECT SUM(Price) FROM Products; → Gives the total of a real (decimal) field, returned as a single row
SUM adds up an integer field and gives one row of output → SELECT SUM(Quantity) FROM Orders;
SUM only works on numeric fields, such as a field of numbers like Mark → SELECT SUM(Mark) FROM Results;
SELECT SUM(Surname) FROM Students; → SUM cannot be used on a text field. Surname is not numeric, so it cannot be added up.
SELECT SUM Score FROM Results; → The field name is missing its brackets. It should be SUM(Score).

Key Term

SUM(field)
Adds up all the values in a numeric field and returns one total, e.g. SELECT SUM(Score) FROM Results; gives one row. It only works on numbers.

Fill in the Blanks

1. SELECT SUM(Score) FROM Results;
Hint: Type the function name that adds up all the values in a numeric field into one total.
2. SELECT SUM(Price) FROM Products;
Hint: Type the keyword that names the table to add up a real number field from.
3. SELECT SUM(Quantity) FROM Orders;
Hint: Type the keyword that starts a query and chooses what to output, here one total of an integer field.
4. -- Total of the Points field SELECT SUM(Points) FROM Players;
Hint: Type the numeric field name the comment says should be added up.
5. -- One total of all Weight values SELECT SUM(Weight) FROM Parcels;
Hint: Type the function that gives a single row holding the total of a real number field.

Spot the Error

Question 1
A SELECT SUM(Score)
B FORM Results
C WHERE Year = 10;
Line B — The keyword is misspelled. It should be FROM Results, because FROM names the table that SUM reads.
Question 2
A SELECT
B SUM Score
C FROM Results;
Line B — SUM needs brackets around the field name. It should be SUM(Score).
Question 3
A SELECT ADD(Score)
B FROM Results
C WHERE Year = 9;
Line A — ADD is not an SQL function. The function that adds up a numeric field is SUM, so it should be SELECT SUM(Score).
Question 4
A SELECT SUM(Mark)
B FROM Exams
C WHERE Subject = Maths;
Line C — Text values in a WHERE condition must be in quotes. It should be WHERE Subject = 'Maths';
Question 5
A SELECT SUM(Price)
B FROM Products
C WHERE Category == 'Tech';
Line C — SQL uses a single = to compare values, not ==. It should be WHERE Category = 'Tech';

Student with a class code? Join your class →