Skip to main content
Admissions guidance, study banks, and career tools — get started on Shalyam

Top Farm per Crop

For each crop return the farm with the highest total tons across all years. Include all farms tied for first. Order by crop.

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.

Rewards · v2.1

Get Exclusive Insights with Every Issue

Join Shalyam Newsletter

Stay ahead in education, research, and innovation—straight to your inbox.