Reputation: 29
test convert column in rows and get count of different values of same column in postresql
Upvotes: 1
Views: 40
Reputation: 222492
You can do conditional aggregation. Postgres supports the standard filter()
clause, that comes handy here:
select
activity_tag,
bank,
count(*) filter(where within_beyond = 'WITHIN') within_count,
count(*) filter(where within_beyond = 'BEYOND') beyond_count
from mytable
group by activity_tag, bank
Upvotes: 1