SQL中case when应用及Decimal类型数据的运算

-----------------------------------

理财计算

insert into lsyw.finance

select cust_num, cust_cn_nm, acct_belg_org, total, l1, 100*(cast(l1 as double)/total) as l1ra, m1l3, 100*(cast(m1l3 as double)/total) as m1l3ra,
m3l6, 100*(cast(m3l6 as double)/total) as m3l6ra, m6l12, 100*(cast(m6l12 as double)/total) as m6l12ra,
m12, 100*(cast(m12 as double)/total) as m12ra from
(
select a.cust_num, c.Cust_Cn_Nm, a.acct_belg_org, count(*) as total,
sum(case when (days(b.due_dt) - days(b.st_int_dt))/30 <= 1 then 1 else 0 end) as l1,
sum(case when (days(b.due_dt) - days(b.st_int_dt))/30 >1 and (days(b.due_dt) - days(b.st_int_dt))/30 <= 3 then 1 else 0 end) as m1l3,
sum(case when (days(b.due_dt) - days(b.st_int_dt))/30 >3 and (days(b.due_dt) - days(b.st_int_dt))/30 <= 6 then 1 else 0 end) as m3l6,
sum(case when (days(b.due_dt) - days(b.st_int_dt))/30 >6 and (days(b.due_dt) - days(b.st_int_dt))/30 <= 12 then 1 else 0 end) as m6l12,
sum(case when (days(b.due_dt) - days(b.st_int_dt))/30 >12 then 1 else 0 end) as m12
from edw.bhif_chrem_fund_sell_dtl a
left join edw.bhif_chrem_fund_prod b
on a.chrem_encd = b.prod_id
left join edw.bhif_indv_cust_basic_info c
on a.cust_num = c.cust_id
where year(b.st_int_dt) != 0001 and year(b.st_int_dt) != 2099 and year(b.due_dt) != 0001 and year(b.due_dt) != 2099 and year(b.due_dt) != 8999
group by cust_num, cust_cn_nm, acct_belg_org

)


-------------------------------------

工资计算

select 
stdgjjennm as 企业名称, count(*) as 企业人数, sum(stdgjjdwam + stdgjjgram)/count(*) as 平均缴存金额, 
sum(stdgjjdwsc)/count(*) as 单位平均缴存比例,sum(stdgjjgrsc)/count(*) as 个人平均缴存比例, 
sum(stdgjjdwam/stdgjjdwsc)/count(*) as 平均工资,
sum(case when stdgjjdwam/stdgjjdwsc >= 0 and stdgjjdwam/stdgjjdwsc < 2000 then 1 else 0 end) as 工资0到2000元人数,
sum(case when stdgjjdwam/stdgjjdwsc >= 2000 and stdgjjdwam/stdgjjdwsc < 3000 then 1 else 0 end) as 工资2000到3000元人数,
sum(case when stdgjjdwam/stdgjjdwsc >= 3000 and stdgjjdwam/stdgjjdwsc < 4000 then 1 else 0 end) as 工资3000到4000元人数,
sum(case when stdgjjdwam/stdgjjdwsc >= 4000 and stdgjjdwam/stdgjjdwsc < 6000 then 1 else 0 end) as 工资4000到6000元人数,
sum(case when stdgjjdwam/stdgjjdwsc >= 6000 and stdgjjdwam/stdgjjdwsc < 8000 then 1 else 0 end) as 工资6000到8000元人数,
sum(case when stdgjjdwam/stdgjjdwsc >= 8000 and stdgjjdwam/stdgjjdwsc < 10000 then 1 else 0 end) as 工资8000到10000元人数,
sum(case when stdgjjdwam/stdgjjdwsc >= 10000 and stdgjjdwam/stdgjjdwsc < 15000 then 1 else 0 end) as 工资10000到15000元人数,
sum(case when stdgjjdwam/stdgjjdwsc >= 15000 and stdgjjdwam/stdgjjdwsc < 20000 then 1 else 0 end) as 工资15000到20000元人数,
sum(case when stdgjjdwam/stdgjjdwsc >= 20000 then 1 else 0 end) as 工资大于20000元人数

from gjj.gjjzh 

where stdgjjdwsc > 0

group by stdgjjennm



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值