DB Quacks SQL Tutorial · Chapter 2

The Great Duck Statistics Quest

Dr. Stork, the village statistician, waddles over with a clipboard. I need to prepare the annual health report! How many ducks do we have? Whats the average age? Whos the youngest and oldest? I need these basic statistics for my report!

Your task

Calculate basic statistics about all ducks from the ducks table: total count, average age, minimum age, and maximum age. You will be using aggregate functions to summarize the data.

Hint

Look for functions that can count rows, calculate averages, and find minimum and maximum values.

Expected result

A single row showing count, average, minimum, and maximum age of all ducks.

Tables

duck_diaries (10 rows)

columntype
diary_idBIGINT
duck_idBIGINT
entry_dateDATE
diary_textVARCHAR
moodVARCHAR

duck_surveys (5000 rows)

columntype
survey_idBIGINT
duck_idBIGINT
ageBIGINT
favorite_foodVARCHAR
favorite_pondBIGINT
swimming_ratingBIGINT
migration_preferenceVARCHAR
social_behaviorVARCHAR
health_statusVARCHAR
activity_levelVARCHAR
survey_dateDATE
survey_locationBIGINT

ducks (15 rows)

columntype
idBIGINT
nameVARCHAR
ageBIGINT
speciesVARCHAR
birth_dateDATE
arrival_dateDATE

ponds (3 rows)

columntype
pond_idBIGINT
pond_nameVARCHAR
location_latDOUBLE
location_lngDOUBLE
capacityBIGINT
featuresVARCHAR[]
amenitiesVARCHAR[]

Database: https://dbquacks.com/data/databases/tutorial.duckdb

This page as markdown: https://dbquacks.com/tutorial/10.md

Start level 10 →

DuckDB docs for this lesson