Species Climate Aggregation
Beginner Mode

Scenario

A wildlife research team maintains separate tables for animal records and the climate classification of each region.

Task

Write a Snowflake SQL query that:

  1. Joins {{ ref("animals") }} with {{ ref("regions") }} on the region column
  2. Groups the results by species and climate
  3. Returns the species, climate, average age (rounded to 2 decimal places), average weight (rounded down to the nearest integer), and total count of animals for each group

Schema

animals

Column Type Description
id String Unique animal identifier
species String Animal species name
age Integer Age in years
weight Float Weight in kilograms
region String Geographic region where the animal lives

regions

Column Type Description
region String Geographic region name
climate String Climate classification for the region

Example

animals:

id species age weight region
1 Wolf 4 45.8 Europe
2 Elephant 25 5200.5 Africa
3 Wolf 6 52.3 Europe
4 Panda 8 110.7 Asia
5 Elephant 30 5400.2 Africa

regions:

region climate
Africa Tropical
Europe Temperate
Asia Subtropical

Expected Output:

species climate avg_age avg_weight total_animals
Elephant Tropical 27.5 5300 2
Panda Subtropical 8.0 110 1
Wolf Temperate 5.0 49 2

Note: Each species belongs to a single region in this dataset, so each group contains one species paired with one climate. The average weight is rounded down to the nearest integer.

Quick Solution

Code Environment

Sign in or try as guest to run your code.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →