I have the table structure below
I want to be able to select the following groups
- farmers who grow between 1 and 3 commodities
- farmers who grow between 4 and 6 commodities
- farmers who grow more than 6 commodities
My resultant query should look like below
I am completely lost as to how to go about this query. I tried
SELECT count(*) AS total,
(SELECT count(farmer_id) from farmer_commodities HAVING count(commodity_id) < 3) AS grow1_3,
(SELECT count(farmer_id) from farmer_commodities HAVING count(commodity_id) BETWEEN 4 AND 6) AS grow4_6,
(SELECT count(farmer_id) from farmer_commodities HAVING count(commodity_id) > 6) as grow_above_6
from farmer_commodities
2
Answers
Can you do this:
Try this