sql · level 1 · unit 5 · lesson 4
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
tidies long decimals into neat answers.
The average bowling score is 108.33333333333333. Nobody needs all those 3s. ROUND(AVG(points), 1) rounds it to one decimal place: 108.3.
Inside ROUND, the first value is the number and the second is how many to keep. Each bracket you open needs closing.
Put several aggregates in one query, each with an alias, for a mini report. Careful: COUNT(*) counts rows, but COUNT(borrower) counts only the boxes that are not NULL.
SELECT COUNT(*) AS games,
MAX(points) AS best,
ROUND(AVG(points), 1) AS average
FROM scores WHERE game = 'bowling'; A long query can spread over several lines, because only the semicolon marks its end.
guess first
Two ways to count. What will this show?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
SELECT COUNT(*) AS books, COUNT(borrower) AS on_loan FROM books;
your turn
Your turn. Tidy up an average.
The average film is 98.71428571428571 minutes long. Type how many decimal places you want to keep in the blank: 0, 1 or 2.
result
Your answer appears here as a table.
fix it
The pet report will not run. Can you fix it?
result
Your answer appears here as a table.
- Read the error. Which word does it point near?
- Each answer in the report is a separate column, and columns need commas between them.
- Add a comma after youngest, then press run.
nailed it
you built a report in one query. :D
ROUND(value, 1)keeps one decimal place.- Several aggregates, each with
AS, make a mini report. COUNT(column)skipsNULL.COUNT(*)counts every row.
new words in your collection
- ROUND
- decimal places
This lesson isn’t saved. A free account remembers every lesson you finish.