Running Totals
Question:
The cats must be ordered by name and will enter an elevator one by one. We would like to know what the running total weight is.
Return: name, running total weight
Order by: name Show Table Schema
Cats:
name | varchar |
breed | varchar |
weight | float |
color | varchar |
age | int |
Correct output but can you use 'over'?
×
Good work!
Over allows us to break down our aggregate functions, it is often used for running totals next question
Desired output:
name | running_total_weight |
Alfie | 5.5 |
Ashes | 10.0 |
Charlie | 14.8 |
Felix | 19.8 |
Millie | 25.2 |
Misty | 30.9 |
Molly | 35.1 |
Oscar | 41.2 |
Puss | 46.3 |
Smokey | 52.4 |
Smudge | 57.3 |
Tigger | 61.1 |
select name, sum(weight) over (order by name) as running_total_weight from cats order by name