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

  • 1
    I do not see the values shown in desured result ('xxx' and other) for country=234 in source data...
    – Akina
    Oct 1 '19 at 8:10
SELECT country, 
       COUNT(state) total,
       SUM(state='xxx') xxx,
       SUM(state='yyy') yyy,
       SUM(state='zzz') zzz
FROM table
GROUP BY country
  • I know it was not your intention, but for your information:This answer was flagged as low-quality because of its length and content. Oct 1 '19 at 10:53
  • @MarcelloMiorelli Thank you for this information. I know the resource doesn't care about helping people at all. They are only interested in beautiful and detailed answers, and their usefulness is not worth attention. If the question author will not understand something - I will explain further. But I'm not going to guess what he might not understand.
    – Akina
    Oct 1 '19 at 11:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.