DB Quacks SQL Tutorial · Chapter 4

DuckCon 2024: Executive Dashboard Madness

CEO duck in a business suit flaps over frantically. Emergency! DuckCon starts tomorrow and the board needs executive data - species visit counts, only species with 3+ visits, sorted by count!

Your task

Show each species and their total visit count, only for species with more than 3 visits, sorted by count. You will be joining the ducks table with 'data/pond_visits.csv', then grouping and filtering the results.

Hint

Combine joining, grouping, filtering groups, and sorting in one query.

Expected result

A table showing species with more than 3 visits, sorted by visit count.

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[]

Files

data/pond_visits.csv (40 rows)

columntype
visit_idBIGINT
duck_idBIGINT
pond_idBIGINT
visit_dateDATE
duration_minutesBIGINT

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

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

Start level 22 →

DuckDB docs for this lesson