AWBNO STATUS
123 DELIVERED
125 DELIVERED
124 RTO
126 RTO
127 NDR
128 NDR
131 DELIVERED
132 DELIVERED
133 NDR
134 DELIVERED
我想以这种方式输出: -
TOTAL DELIVERED RTO NDR
10 5 2 3
答案 0 :(得分:3)
您可以根据以下状态执行条件聚合:
select
count(*) total,
count(case when status = 'DELIVERED' then 1 end) DELIVERED,
count(case when status = 'RTO' then 1 end) RTO,
count(case when status = 'NDR' then 1 end) NDR
from your_table;