简体   繁体   中英

How to fetch data from a column and display that data using 2 columns in PostgreSQL?

Here is the example table:

输入表

And I want output like this:

输出

Use conditional aggregation:

select wf_name,
    count(*) filter(where crt_by = 'ADHOC') adhoc,
    count(*) filter(where crt_by = 'SCHEDULE') schedule
from mytable
group by wf_name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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