简体   繁体   English

转换行中的列并获取 postresql 中同一列的不同值的计数

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

测试转换行中的列并获取 postresql 中同一列不同值的计数

You can do conditional aggregation.您可以进行条件聚合。 Postgres supports the standard filter() clause, that comes handy here: Postgres 支持标准的filter()子句,在这里很方便:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM