I have one table User
, with column UserId, Country and State.
User table data is as below
-------------------------------
| UserId | Country | State |
--------------------------------
| AAA | US | AR |
| BBB | GB | LN |
| BBB | MX | MC |
| AAA | MX | CH |
| CCC | GB | LE |
| CCC | | IL |
--------------------------------
Expected result is as below,
---------------------------------------------------------------------
UserId totalcountry US MX GB TotalState AR LN MC CH LE IL
----------------------------------------------------------------------
AAA 2 1 1 0 2 1 0 0 1 0 0
BBB 2 0 1 1 2 1 1 0 0 0
CCC 1 0 0 1 0 0 0 0 0 1 1
-----------------------------------------------------------------------