Source File: ex18.sql

These are excerpts shown as snippets from a main file named ex18.sql. They generally only make sense in the context of the exercise text, but they're shown here separated by H2 heading tags for audible readers like NV Access.

Snippet avg

*/

/* select the average age of every person */
select avg(age) from person;

/* select the average age of every pet */
select avg(age) from pet;

/* select the average age of every breed by dead or alive */
select breed, dead, avg(age) from pet group by breed, dead;

Snippet sum

*/

select sum(age) from person;

select sum(age) from pet;

select breed, sum(dead), sum(age) from pet where dead = 1 group by breed, dead;

Snippet min

*/

select min(age), max(age) from person;

select min(age), max(age) from pet;

select breed, dead, min(age), max(age) from pet 
    where age > 0
    group by breed, dead;