user12443544
user12443544

Reputation: 29

convert column in rows and get count of different values of same column in postresql

test convert column in rows and get count of different values of same column in postresql

Upvotes: 1

Views: 40

Answers (1)

GMB
GMB

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

Related Questions