在ibatis中写的一段sql脚本

 sel indexId,item,value01,value02,value03
  from
(
  sel '7' indexId
   ,'新增通话用户三比' item
   ,a.value03 value01
   ,b.value03 value02
   ,case  when b.value03 = 0.00 then 0.00
    else a.value03-b.value03
   end as value03
  from
   (
    
     sel
     zeroifnull(sum(new_user_cnt )) value01
     ,zeroifnull(sum(new_user_cnt ))
     +zeroifnull(sum(unicom_gsm_new_user ))
     +zeroifnull(sum(unicom_cdma_new_user ))
     +zeroifnull(sum(phs_new_user_cnt )) value02
          ,case when value02=0 then 0.00
      else
     (100*1.00*value01)/value02
     end  value03
     from dwpmvw.VW_fact_section_kpi_mon
     where acyc_id = #acyc_id#
     and city_code = #cityCode#
   )a,
   (
     sel
     zeroifnull(sum(new_user_cnt )) value01
     ,zeroifnull(sum(new_user_cnt ))
     +zeroifnull(sum(unicom_gsm_new_user))
     +zeroifnull(sum(unicom_cdma_new_user))
     +zeroifnull(sum(phs_new_user_cnt)) value02
          ,100*1.00*(value01)/value02 value03
     from dwpmvw.VW_fact_section_kpi_mon
     where acyc_id=#acyc_id_last_month#
     and city_code = #cityCode#
   )b
   
  
 union all
  
 sel '3' indexId
  ,'通话用户数' item
  ,a.value01 value01
  ,b.value01 value02
  ,case when b.value01=0 then 0.00
   else 1.00*100*(a.value01-b.value01)/b.value01
   end  value03
 from (
     sel zeroifnull(sum(using_user_cnt)) value01
     from dwpmvw.VW_fact_section_kpi_mon where acyc_id=#acyc_id#
     and city_code = #cityCode#
    ) a,(
       sel zeroifnull(sum(using_user_cnt)) value01
       from dwpmvw.VW_fact_section_kpi_mon where acyc_id=#acyc_id_last_month#
       and city_code = #cityCode#
      ) b
    
 union all
 
 sel '1' indexId
   ,'新增通话用户数' item
   ,a.value01 value01
   ,b.value01 value02
   ,case when b.value01=0 then 0.00
    else (100*1.00*(a.value01-b.value01)/b.value01)
    end as value03
 from (
     sel zeroifnull(sum(new_user_cnt)) value01
     from dwpmvw.VW_fact_section_kpi_mon
     where acyc_id=#acyc_id# 
     and city_code = #cityCode#
    ) a,
    (
     sel zeroifnull(sum(new_user_cnt)) value01
     from dwpmvw.VW_fact_section_kpi_mon
     where acyc_id=#acyc_id_last_month#
     and city_code = #cityCode#
    )b
    
 union all
 
 sel '2' indexId
   ,'净增通话用户数' item
   ,a.value01 value01
   ,b.value01 value02
    ,case when b.value01=0 then 0.00
     else ( 100*1.00*(a.value01-b.value01)/b.value01)
     end as value03
 from
   (
     sel value01 from
     (
       sel a.value01-b.value01 value01 from
       (
        sel zeroifnull(sum(using_user_cnt)) value01 from dwpmvw.VW_fact_section_kpi_mon
        where acyc_id = #acyc_id# 
        and city_code = #cityCode#
       ) a,
       (
        sel zeroifnull(sum(using_user_cnt)) value01 from dwpmvw.VW_fact_section_kpi_mon
        where acyc_id = #acyc_id_last_month#
        and city_code = #cityCode#
       ) b
     )ff
   )a,
   (
     sel value01 from
     (
       sel a.value01-b.value01 value01 from
       (
        sel zeroifnull(sum(using_user_cnt)) value01 from dwpmvw.VW_fact_section_kpi_mon
        where acyc_id = #acyc_id_last_month#
        and city_code = #cityCode#
       ) a,
       (
        sel zeroifnull(sum(using_user_cnt)) value01 from dwpmvw.VW_fact_section_kpi_mon
        where acyc_id = #acyc_id_last_last_month#
        and city_code = #cityCode#
       ) b
     )ff
    )b
    
    
 union all
 
 sel '4' indexId
   ,'通话时长' item
   ,a.value01 value01
   ,b.value01 value02
   ,case when b.value01=0 then 0
   else (100*1.00*(a.value01-b.value01)/b.value01)
   end as value03
 from
   (
     sel zeroifnull(sum(times1)) value01
     from dwpmvw.VW_fact_section_kpi_mon
     where acyc_id = #acyc_id# 
     and city_code = #cityCode#
   )a,
   (
     sel zeroifnull(sum(times1)) value01
     from dwpmvw.VW_fact_section_kpi_mon
     where acyc_id = #acyc_id_last_month#
     and city_code = #cityCode#
   )b
   
 union all
 
 sel  '5' indexId
   ,'运营收入' item
   ,a.value01/100 value01
   ,b.value01/100 value02
   ,case when b.value01=0 then 0.00
    else (100*1.00*(a.value01-b.value01)/b.value01)
    end  value03
 from
   (
    sel zeroifnull(sum(fee_chrg)) value01
    from dwpmvw.VW_fact_section_kpi_mon
    where acyc_id = #acyc_id#
    and city_code = #cityCode#
   )a,
   (
    sel zeroifnull(sum(fee_chrg)) value01
    from dwpmvw.VW_fact_section_kpi_mon
    where acyc_id = #acyc_id_last_month#
    and city_code = #cityCode#   
   )b
 
 union all
 
 sel '6' indexId
   ,'通话用户三比' item
   ,a.value03 value01
   ,b.value03 value02
   ,case  when b.value03 = 0.00 then 0.00
    else 1.00*100*(a.value03-b.value03)/b.value03
   end as value03
 from
   (
     sel
     zeroifnull(sum(using_user_cnt)) value01
     ,zeroifnull(sum(using_user_cnt))
     +zeroifnull(sum(unicom_gsm_user_cnt))
     +zeroifnull(sum(unicom_cdma_user_cnt))
     +zeroifnull(sum(phs_user_cnt)) value02
          ,
     case when value02=0 then 0.00
     else
     (100*1.00*value01)/value02
     end  value03
     from dwpmvw.VW_fact_section_kpi_mon
     where acyc_id=#acyc_id#
     and city_code = #cityCode#
   )a,
   (
     sel
     zeroifnull(sum(using_user_cnt)) value01
     ,zeroifnull(sum(using_user_cnt))
     +zeroifnull(sum(unicom_gsm_user_cnt))
     +zeroifnull(sum(unicom_cdma_user_cnt))
     +zeroifnull(sum(phs_user_cnt)) value02
          ,(100*1.00*value01)/value02 value03
     from dwpmvw.VW_fact_section_kpi_mon
     where acyc_id=#acyc_id_last_month#
     and city_code = #cityCode#
   )b

)zz order by 1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值