68. Find the Last Climber per Mountain
Beginner Mode
Scenario
You work with a mountain climbing registry that tracks which climbers have summited each mountain and when.
Task
Write a Snowflake SQL query that:
- Joins
{{ ref("climbers") }}with{{ ref("mountains") }}on the mountain name - For each mountain, finds the climber with the most recent
climb_date - Returns
mountain_name, the climber's name aslast_climber_name, the date aslast_climb_date, and the time aslast_climb_time - Excludes any mountains that have no climbing records
Schema
mountains
| Column | Type | Description |
|---|---|---|
| name | String | Name of the mountain |
| height | Integer | Height in meters |
| country | String | Country where the mountain is located |
| range | String | Mountain range it belongs to |
climbers
| Column | Type | Description |
|---|---|---|
| climber_name | String | Name of the climber |
| mountain_name | String | Name of the mountain climbed |
| climb_date | Date | Date of the climb |
| climb_time | Double | Duration of the climb in hours |
Example
mountains:
| name | height | country | range |
|---|---|---|---|
| Mount Rainier | 4392 | USA | Cascades |
| Matterhorn | 4478 | Switzerland | Alps |
| Mount Olympus | 2917 | Greece | Olympus |
climbers:
| climber_name | mountain_name | climb_date | climb_time |
|---|---|---|---|
| Alice | Mount Rainier | 2021-06-10 | 7.5 |
| Bob | Mount Rainier | 2023-08-15 | 6.0 |
| Carol | Matterhorn | 2022-07-20 | 11.0 |
| Dave | Matterhorn | 2024-01-05 | 9.5 |
Expected Output:
| mountain_name | last_climber_name | last_climb_date | last_climb_time |
|---|---|---|---|
| Mount Rainier | Bob | 2023-08-15 | 6.0 |
| Matterhorn | Dave | 2024-01-05 | 9.5 |
Note: Mount Olympus has no climbing records, so it does not appear in the output. For each mountain with climbers, only the row with the most recent
climb_dateis returned.
Code Environment
Sign in or try as guest to run your code.
Essential
SQL 0/33
Spark 0/20
Snowflake 0/22
Python 0/24
Need more practice in this area? Explore more questions →
Bloomberg
Revolut
Accenture
Adobe
Google
LinkedIn
Samsung
Datadog
Wix
Dropbox
Meta
OpenAI
Hulu
Uber
X
DoorDash
Anthropic
Amazon
ActivisionBlizzard
Vercel
Crypto.Com
Zscaler
DeutscheBank
Apple
GoDaddy
GitLab
BMW
PayPal
Snowflake
AMD
Twilio
Atlassian
JPMorgan
NVIDIA
IBM
Databricks
Coinbase
Cisco
Robinhood
Twitter
Microsoft
Palantir
Netflix
VMware
Cloudflare
Stripe
Lyft
Salesforce
GitHub
Airbnb
Walmart
SAP
HashiCorp
Instacart
Mastercard
Intel
Visa
Tesla