zoukankan      html  css  js  c++  java
  • case when 嵌套,行专列

    case  when Expendunit is null then (case when Expendunit1 is null then (case when Expendunit2 is null then (case when Expendunit3 is null then Expendunit4 else Expendunit3 end) else Expendunit2 end) else Expendunit1 end) else Expendunit end Expendunit

    select case  when Expendunit is null then (case when Expendunit1 is null then (case when Expendunit2 is null then (case when Expendunit3 is null then Expendunit4 else Expendunit3 end) else Expendunit2 end) else Expendunit1 end) else Expendunit end Expendunit,aa.rmb,bb.rmb1,cc.rmb2,dd.rmb3,ee.rmb4 from (select top 100000 Expendunit,sum(RMB) rmb,case Settletype when 0 then '电汇'  when 1 then '承兑' when 2 then '现金' when 3 then '手机支付' when 4 then '转账'  end Settletype from Expenditure where businessdate >='2019-08-01 00:00:00.000' and businessdate<='2019-08-31 00:00:00.000' and settletype=2 group by  Expendunit,Settletype order by Expendunit,Settletype) aa
    full outer join (select top 100000 Expendunit Expendunit1,sum(RMB) rmb1,case Settletype when 0 then '电汇'  when 1 then '承兑' when 2 then '现金' when 3 then '手机支付' when 4 then '转账'  end Settletype from Expenditure where businessdate >='2019-08-01 00:00:00.000' and businessdate<='2019-08-31 00:00:00.000' and settletype=0 group by  Expendunit,Settletype order by Expendunit1,Settletype) bb on aa.Expendunit=bb.Expendunit1
    full outer join (select top 100000 Expendunit Expendunit2,sum(RMB) rmb2,case Settletype when 0 then '电汇'  when 1 then '承兑' when 2 then '现金' when 3 then '手机支付' when 4 then '转账'  end Settletype from Expenditure where businessdate >='2019-08-01 00:00:00.000' and businessdate<='2019-08-31 00:00:00.000' and settletype=1 group by  Expendunit,Settletype order by Expendunit2,Settletype) cc on bb.Expendunit1=cc.Expendunit2
    full outer join(select top 100000 Expendunit Expendunit3,sum(RMB) rmb3,case Settletype when 0 then '电汇'  when 1 then '承兑' when 2 then '现金' when 3 then '手机支付' when 4 then '转账'  end Settletype from Expenditure where businessdate >='2019-08-01 00:00:00.000' and businessdate<='2019-08-31 00:00:00.000' and settletype=3 group by  Expendunit,Settletype order by Expendunit3,Settletype) dd on cc.Expendunit2=dd.Expendunit3
    full outer join(select top 100000 Expendunit Expendunit4,sum(RMB) rmb4,case Settletype when 0 then '电汇'  when 1 then '承兑' when 2 then '现金' when 3 then '手机支付' when 4 then '转账'  end Settletype from Expenditure where businessdate >='2019-08-01 00:00:00.000' and businessdate<='2019-08-31 00:00:00.000' and settletype=4 group by  Expendunit,Settletype order by Expendunit4,Settletype) ee on dd.Expendunit3=ee.Expendunit4
    union all
    select '合计' Expendunit,sum(rmb) rmb,sum(rmb1) rmb1,sum(rmb2) rmb2,sum(rmb3) rmb3,sum(rmb4) rmb4 from (select case  when Expendunit is null then (case when Expendunit1 is null then (case when Expendunit2 is null then (case when Expendunit3 is null then Expendunit4 else Expendunit3 end) else Expendunit2 end) else Expendunit1 end) else Expendunit end Expendunit,aa.rmb,bb.rmb1,cc.rmb2,dd.rmb3,ee.rmb4 from (select top 100000 Expendunit,sum(RMB) rmb,case Settletype when 0 then '电汇'  when 1 then '承兑' when 2 then '现金' when 3 then '手机支付' when 4 then '转账'  end Settletype from Expenditure where businessdate >='2019-08-01 00:00:00.000' and businessdate<='2019-08-31 00:00:00.000' and settletype=2 group by  Expendunit,Settletype order by Expendunit,Settletype) aa
    full outer join (select top 100000 Expendunit Expendunit1,sum(RMB) rmb1,case Settletype when 0 then '电汇'  when 1 then '承兑' when 2 then '现金' when 3 then '手机支付' when 4 then '转账'  end Settletype from Expenditure where businessdate >='2019-08-01 00:00:00.000' and businessdate<='2019-08-31 00:00:00.000' and settletype=0 group by  Expendunit,Settletype order by Expendunit1,Settletype) bb on aa.Expendunit=bb.Expendunit1
    full outer join (select top 100000 Expendunit Expendunit2,sum(RMB) rmb2,case Settletype when 0 then '电汇'  when 1 then '承兑' when 2 then '现金' when 3 then '手机支付' when 4 then '转账'  end Settletype from Expenditure where businessdate >='2019-08-01 00:00:00.000' and businessdate<='2019-08-31 00:00:00.000' and settletype=1 group by  Expendunit,Settletype order by Expendunit2,Settletype) cc on bb.Expendunit1=cc.Expendunit2
    full outer join(select top 100000 Expendunit Expendunit3,sum(RMB) rmb3,case Settletype when 0 then '电汇'  when 1 then '承兑' when 2 then '现金' when 3 then '手机支付' when 4 then '转账'  end Settletype from Expenditure where businessdate >='2019-08-01 00:00:00.000' and businessdate<='2019-08-31 00:00:00.000' and settletype=3 group by  Expendunit,Settletype order by Expendunit3,Settletype) dd on cc.Expendunit2=dd.Expendunit3
    full outer join(select top 100000 Expendunit Expendunit4,sum(RMB) rmb4,case Settletype when 0 then '电汇'  when 1 then '承兑' when 2 then '现金' when 3 then '手机支付' when 4 then '转账'  end Settletype from Expenditure where businessdate >='2019-08-01 00:00:00.000' and businessdate<='2019-08-31 00:00:00.000' and settletype=4 group by  Expendunit,Settletype order by Expendunit4,Settletype) ee on dd.Expendunit3=ee.Expendunit4) ff

  • 相关阅读:
    安装rocketmq并配置管理界面
    centos7搭建xl2tpd
    搭建fastfds+nginx
    申请SSL域名证书
    nginx返回状态码
    搭建v/2/ray和sserver
    第十一周课程总结
    第八周课程总结
    实验报告七&&课程总结
    第八周课程报告&&实验报告六
  • 原文地址:https://www.cnblogs.com/passerlee/p/11418940.html
Copyright © 2011-2022 走看看