country-category male_cnt female_cnt total_cnt
US north 100 80 180
US south 100 80 180
US east 100 80 180
US west 100 80 180
IN north 100 80 180
IN south 100 80 180
IN east 100 80 180
IN west 100 80 180
MX north 100 80 180
MX south 100 80 180
MX east 100 80 180
JP south 100 80 180
JP west 100 80 180
I need to convert the 4 rows for each country into a single row output. when the category is north/south I need to pick the male_cnt and when the category east/west I need to pick the female_cnt. If a category is not available for a country the value should null. The order of category is important in the output. It can be any order but for all records, it should remain the same.
Desired output:
US,north,100,south,100,east,80,west,80
IN,north,100,south,100,east,80,west,80
MX,north,100,south,100,east,80,west,
JP,north,,south,100,east,,west,80
US,100,100,80,80
IN,100,100,80,80
MX,100,100,,80,,
JP,,100,,80
Please assist. I used CONCAT_WS and COLLECT_SET so far to achieve the desired output but not getting the right output.