0

I just cant seem 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: enter image description here

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!

1 Answer 1

2
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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.