SQL Number of Members in each country whose preference game is set to NES
EXPECTED OUTPUT
COUNT(AUD) COUNT(EUR) COUNT(IND) COUNT(LAO) COUNT(USA) COUNT(ZWE)
3 2 0 0 2 1
Here is the SQL fiddle
http://sqlfiddle.com/#!9/a15ec9f/3
>Solution :
We pivot.
select *
from t
pivot(count(MEMBER_ID) for COUNTRY_ID in('AU' as "count(AU)", 'US' as "count(US)", 'LAO' as "count(LAO)", 'IND' as "count(IND)", 'DE' as "count(DE)", 'ZW' as "count(ZW)")) p
| count(AU) | count(US) | count(LAO) | count(IND) | count(DE) | count(ZW) |
|---|---|---|---|---|---|
| 3 | 7 | 0 | 0 | 4 | 2 |