Yield Change Year over Year
Medium
Crop Yield Analysis
For each farm and crop, return the change in tons versus the previous year for which that farm and crop has data. Show only rows that have a previous year. Order by farm name, crop, year.
Table schema
Farms(farm_id INT PRIMARY KEY, name VARCHAR(20), region VARCHAR(10))
Harvests(harvest_id INT PRIMARY KEY, farm_id INT, crop VARCHAR(10), year INT, tons INT, hectares INT)Sample data
Farms
farm_id | name | region
1 | Green Acres | North
2 | Sun Fields | North
3 | River Bend | South
Harvests
harvest_id | farm_id | crop | year | tons | hectares
1 | 1 | Wheat | 2024 | 100 | 20
2 | 1 | Wheat | 2025 | 120 | 20
3 | 2 | Rice | 2025 | 90 | 10
4 | 2 | Wheat | 2025 | 60 | 10
5 | 3 | Rice | 2024 | 80 | 16
6 | 3 | Rice | 2025 | 64 | 16
Discussion
No discussions yet.
Shalyam Support
Hi! Ask us anything — we'll reply on WhatsApp or Telegram within 24 hours.