I have table:
Country:
id | name | group| type
1 | USA | 1 | 0
2 | Germany | 2 | 1
3 | France | 2 | 0
4 | China | 1 | 1
5 | Japan | 3 | 0
6 | Italy | 1 | 1
7 | Mexico | 1 | 0
8 | Columbia | 3 | 0
9 | Taiwan | 2 | 1
...
Now I would like receive percentange of positive "type" with grouped by "group" field.
So results should looks like:
group| percentage
1 | 50% -- 0 + 1 + 1 + 0 = 2/4 = 50%
2 | 66% -- 1 + 0 + 1 = 2/3 = 66%
3 | 0% -- 0 + 0 = 0/2 = 0%
How is the best way for this? Is this possible in one query? I am newbie in MySQL and I don't have any idea. I can only:
SELECT group, (????) as percentage FROM country GROUP BY group;