case when 统计

with a as(
select distinct
t.cus_type3,
sum(case when c.cat_no like 'A'||'%' then c.con_amt  else 0 end)  over (partition by t.cus_type3) ANUM3 ,
sum(case when c.cat_no like 'B'||'%' then c.con_amt  else 0 end)  over (partition by t.cus_type3) BNUM3,
sum(case when c.cat_no like 'C'||'%' then c.con_amt  else 0 end)  over (partition by t.cus_type3) CNUM3,
sum(case when t.cus_type3 ='01' then c.con_amt else 0 end ) over (partition by t.cus_type3 ) zy,
sum(case when t.cus_type3 ='02' then c.con_amt else 0 end ) over (partition by t.cus_type3 )sj,
sum(case when t.cus_type3 ='03' then c.con_amt else 0 end ) over (partition by t.cus_type3 )df,
sum(case when t.cus_type3 ='04' then c.con_amt else 0 end ) over (partition by t.cus_type3 )xq
from customer t,contract_dtl c
where t.cus_no= c.cus_no
)
select a.*,(select sum(ANUM3) from a) A3SUM,
(select sum(BNUM3) from a) B3SUM,
(select sum(CNUM3) from a) C3SUM,
(select sum(zy)+sum(sj)+sum(df)+sum(xq)from a) SUMAll3
from a

你可能感兴趣的:(case when)