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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值