Mineral Extraction by Location
Beginner Mode

Scenario

You work for a mining company that tracks rare mineral extraction across multiple global sites.

Task

Write a Snowflake SQL query that:

  1. Joins {{ ref("mines") }} with {{ ref("extractions") }} on the mine identifier
  2. Calculates total_quantity as the sum of quantity grouped by location and mineral
  3. Returns only the location, mineral, and total_quantity columns
  4. Sorts results by location ascending, then by mineral ascending

Schema

mines

Column Type Description
id Integer Unique identifier for the mine
name String Name of the mine
location String Country where the mine operates

extractions

Column Type Description
mine_id Integer References the mine's id
date Date Date of the extraction
mineral String Name of the extracted mineral
quantity Integer Quantity extracted in kilograms

Example

mines:

id name location
1 Ridgeback Mine Peru
2 Sunstone Mine Norway
3 Deepcore Mine Peru
4 Ironveil Mine Ghana

extractions:

mine_id date mineral quantity
1 2024-03-10 Copper 450
2 2024-03-10 Titanium 300
3 2024-03-10 Copper 550
4 2024-03-11 Bauxite 700
1 2024-03-11 Copper 600
2 2024-03-11 Titanium 400

Expected Output:

location mineral total_quantity
Ghana Bauxite 700
Norway Titanium 700
Peru Copper 1600

Note: Peru has two mines (Ridgeback and Deepcore) both extracting Copper, so their quantities are summed together. Norway's two Titanium extractions on different dates are also combined.

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 →