Skip to content
Advertisement

Group by combination count in postgresql

I have a database table as like table_name (participant_member) :

enter image description here

dataset and output formate link

I need combination based group by unique count for example if a member already stay in purpose p1 then it will not count inside p1,p2 combinaton if the member_id contain the purpose p1 and p2 then it will count inside p1,p2 enter image description here I have tryied using this query

This output generate based on the test input dataset.

I have tried a sql query but it does not give me the appropriate output as i like . its doesnt give me the unique one

Note: I am using postgres database

Advertisement

Answer

I think the problem was with cte you should group by member to get the purpose combination of every member then count the member of every combination:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement