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

  • 相关阅读:
    hdu 2222 Keywords Search 模板题
    AC自动机 (模板)
    7. 通过鼠标右键改变视角
    NGUI所见即所得之UIAtlasMaker , UIAtlas (2)
    6. 通过鼠标滑轮控制“镜头远近”
    5. Unity脚本的执行顺序
    4. 在Inspector面板中显示类中变量+ 拓展编辑器
    NGUI 的使用教程与实例(入门)(1 )
    1. 通过移动鼠标旋转摄像机观察模型
    C#面试题
  • 原文地址:https://www.cnblogs.com/passerlee/p/11418940.html
Copyright © 2011-2022 走看看