DB Quacks SQL Tutorial · Chapter 7

Finding Nemo: A Spatial Odyssey

Deep-sea explorer duck surfaces in scuba gear. Dude! Im Nemos cousin, mapping the data ocean floor! Duck locations are latitude/longitude coordinates stored in our duck_locations.csv file. Find which ducks live within 10km of Central Pond using spatial extension!

Your task

Install spatial extension and find ducks within 10km of Central Pond using the 'data/duck_locations.csv' file. The pond location coordinates are provided. You will be performing geographical distance calculations.

Hint

You need to install an extension first, then use spatial functions to calculate distances between geographical points.

Expected result

A table showing duck names within 10km of Central Pond (pond_id: 1).

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

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

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

Start level 36 →

DuckDB docs for this lesson