Summing all values using the SUM Function.

By Alan Hylands — 1 minute read

The SUM function allows you to do a summary calculation on a particular column in your data table. No wildcards here, we MUST specify the individual column we want to summarise.

The easiest way to think about the SUM function is to use it to add up all of the values in a particular column. If we want to find the total number of international caps for our football players, our SQL query would look like this:

IDPlayerNameIntlCaps
1Peter Shilton125
2Pat Jennings119
3Bobby Moore108
4Diego Maradona91
SELECT SUM(IntlCaps) 
FROM footballers;

(Answer: 443)

Quiz Time.

The Question.

It's not all about the price tag when it comes to making these movies. Not unless you are a studio executive looking to see how big of a cheque you are going to have to write to get one made.

Let's pretend you are Marvel's accountant for a second. Get the total budget for all four Avengers movies (and remember these budget figures are in MILLIONS of US dollars).

The Data.

Table Name: movies
idtitlerelease_yearbudget
1The Avengers2012220
2Avengers: Age of Ultron2015250
3Avengers: Infinity War2018321
4Avengers: Endgame2019356

The Editor.


Run SQL


Show Answer
Try the next lesson