开发者

Problem with MySQL join query

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:

Problem with MySQL join query

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜