Mysql – Get 2 counts in single query

aggregategroup byMySQLmysql-5.5

I need to get count of 2 columns with group by

enter image description here

This is my sample data

I need to get count of persons from particular state and count of persons from particular country

My output should be like

enter image description here

I need to manipulate data like this; how to create query for this

Best Answer

SELECT country, 
       COUNT(state) total,
       SUM(state='xxx') xxx,
       SUM(state='yyy') yyy,
       SUM(state='zzz') zzz
FROM table
GROUP BY country