Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Postgresql how to transform and summarize rows count

$
0
0

This is my data

with _temp_data as (select     unnest(ARRAY['A','B','A','A']) as hobbies_1    ,unnest(ARRAY['E','F','A','F']) as hobbies_2)select * from _temp_data

Input data:

hobbies_1|hobbies_2|---------+---------+A        |E        |B        |F        |A        |A        |A        |F        |

I want to transform this table into single row combination like this

hobbies_1      |  hobbies_2{'A':3,'B':1}  |{'E':1,'F':2,'F':1}

Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>