sql · level 1 · unit 5 · lesson 2
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
adds a column up. finds its average.
SUM(points) adds up every value in the points column and hands back the total. Like COUNT, it squashes many rows into one answer.
AVG(points) finds the average: the total, divided by how many values there are. Averages often have decimals, even when every value is a whole number.
You can put a calculation inside the brackets. SUM(price * stock) works out each row first, then adds up the answers.
SELECT SUM(points) AS total, AVG(points) AS average FROM scores WHERE game = 'darts'; SUM and AVG skip any NULL boxes, so empty values do not count.
guess first
Snacks on the shelf. What is the total?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
SELECT SUM(stock) AS snacks_left FROM snacks;
your turn
Your turn. Total up one player.
Type a player's name between the quotes: Mia, Leo, Ava or Sam. The query adds up all of their points.
result
Your answer appears here as a table.
fix it
This average looks far too big. Can you fix it?
result
Your answer appears here as a table.
- 210 is far too big for an average darts score. Which function did the query use?
SUMadds the points up. You want them added up and then shared out evenly.- Change SUM to AVG, then press run.
nailed it
you added up and averaged a column. :D
SUMadds up every value in a column.AVGfinds the average, often with decimals.- Calculations can go inside the brackets, like
SUM(price * stock).
new words in your collection
- SUM
- AVG
This lesson isn’t saved. A free account remembers every lesson you finish.