样本数据 :
with t1 as(
select 'EM0004357P' ord_deal_code, 'PRORATE' ort_method from dual union all
select 'EM0004357P' ord_deal_code, 'COMPLETE' ort_method from dual union all
select 'EM0004357P' ord_deal_code, 'PRORATE' ort_method from dual union all
select 'EM0004357P' ord_deal_code, 'RANDOM' ort_method from dual union all
select 'EM0004357P' ord_deal_code, 'RANDOM' ort_method from dual
)
询问:
SELECT count(decode(o.ort_method, 'PRORATE', 1)) as prorate
, count(decode(o.ort_method, 'COMPLETE', 1)) as complete
, count(decode(o.ort_method, 'RANDOM', 1)) as random
FROM t1 o
WHERE o.ord_deal_code = 'EM0004357P';
结果:
Prorate complete random
2 1 2