Summing all values using the SUM Function.
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:
ID | PlayerName | IntlCaps |
---|---|---|
1 | Peter Shilton | 125 |
2 | Pat Jennings | 119 |
3 | Bobby Moore | 108 |
4 | Diego Maradona | 91 |
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.
The Editor.
Show Answer
The Answer.
Correct SQL:
SELECT SUM(budget) FROM movies;