Refresher on Aggregates
Question:
You will need to know aggregate functions before attempting the other questions. We would like to find the total weight of cats grouped by age. But only return those groups with a total weight larger than 12.
Return: age, sum(weight)
Order by: age
Show Table
Cats:
| name | varchar |
| breed | varchar |
| weight | float |
| color | varchar |
| age | int |
Show Desired Output
Desired output:
| age | total_weight |
| 2 | 19.60 |
| 4 | 15.80 |
| 5 | 15.40 |
Query Window:
Correct output but can you use 'group by'?
×
Good work!
Group by and Having are required by aggregate functions like avg(), sum(), max(), min(). Aggregate functions are used for finding sums and averages. next question
Show Answer
Answer:
select
age, sum(weight) as total_weight
from cats group by age having sum(weight) > 12 order by age