DB Quacks SQL Tutorial · Chapter 7

Endgame - Data Assembly

Festival day arrives! All your Pondville friends gather at the floating festival stage. Duckbert! calls Professor Shellbert. Ducks are arriving from everywhere - families reuniting, interdimensional visitors, cloud communities! We need perfect timing coordination. The Doctor Duck materializes with festival schedules. Match everyones current location with migration history for perfect arrival timi…

Your task

Use ASOF JOIN to create perfect timing by matching current duck locations from 'data/duck_locations.csv' with their migration history from 'data/migration_history.parquet'. You will be finding the most recent migration record for each duck.

Hint

Look for a special type of join that can match records based on time relationships, finding the most recent record that occurred before or at a given time.

Expected result

A table showing current duck locations matched with their most recent migration records.

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/duck_locations.csv (15 rows)

columntype
duck_idBIGINT
current_dateDATE
duck_latitudeDOUBLE
duck_longitudeDOUBLE
last_seenTIMESTAMP

data/migration_history.parquet (20 rows)

columntype
duck_idBIGINT
migration_dateDATE
destinationVARCHAR
distance_kmDOUBLE
seasonVARCHAR

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

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

Start level 38 →

DuckDB docs for this lesson