I just cant seem开发者_C百科 to get my head around this problem, so thought I would ask it here. The system I'm making is a system where farmers can claim subsidy for the crops / animals. Each farmer is allocated to a specific region. What I need to do is to get the total claims made by each region. Here's my tables:
So what I need to do again is to take the sum of total from the claims table but group that by region. I already know how to do it for one specific region, but I would like to select all the regions in one query.
Thanks for your help, much appreciated!
select
farmer.region_id,
sum( claims.total ) TotalClaims
from
claims
join farmer
on claims.farmer_id = farmer.id
join regions
on farmer.region_id = regions.id
group by
farmer.region_id
精彩评论