DB Quacks SQL Tutorial · Chapter 6

The Lord of the Rings: ROLLUP of Power

Gandalf the Grey Duck appears with a glowing staff. One report to rule them all! The Council needs visit counts by species AND pond, plus subtotals by species, AND grand total. Use ancient ROLLUP magic!

Your task

Create a hierarchical report showing visit counts with subtotals by species and a grand total by joining the ducks table with 'data/pond_visits.csv'. You will be creating multiple levels of aggregation.

Hint

Look for a GROUP BY modifier that can create multiple levels of subtotals automatically.

Expected result

A hierarchical report with visit counts, species subtotals, and grand total.

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/33.md

Start level 33 →

DuckDB docs for this lesson