开发者

Problem with MySQL join query

开发者 https://www.devze.com 2023-02-14 01:57 出处:网络
I just cant seem开发者_C百科 to get my head around this problem, so thought I would ask it here.

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

精彩评论

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