Skip to content
basic aggregate functions

Introducing: sum()


This simple query will display the time spent out on all all the walks.
select minutestaken from walk
Loading…
Think about this requirement:
Some people have been out on all the walks; how long did they spend walking all together?
A calculation which adds up the all the minutes taken column value in every row is needed.

Using the sum() aggregate function


Here is how the SQL sum() function could be used to produce the total.
select sum(minutestaken) as "walking time total" from walk
Loading…
take care not to confuse SUM and COUNT ..
select count(minutestaken) as "walking time total" from walk
.. this query would simply return 8, can you explain why?

Using sum() aggregate function


save your working code in application express
Try a simple version first, like: display all rows and columns. Then introduce sum(), then add an alias
some queries will need a where clause

How many people have walked in the rain?
How far did a walker go if they completed all the coastal routes?
How long would it take to walk all the hill and mountain routes?

Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.