sql case嵌套的示例

    技术2022-05-11  24

    create view v_kucun as( select st.date "日期" , round(sum(case st.c_type when 106 then case st.p_type when 102 then st.ins - st.outs end end), 2) "甲班炼钢库存" , round(sum(case st.c_type when 106 then case st.p_type when 103 then st.ins - st.outs end end), 2) "甲班连铸库存" , round(sum(case st.c_type when 106 then case st.p_type when 104 then st.ins - st.outs end end), 2) "甲班炉卷库存" , round(sum(case st.c_type when 106 then case st.p_type when 105 then st.ins - st.outs end end), 2) "甲班热连库存" , round(sum(case st.c_type when 107 then case st.p_type when 102 then st.ins - st.outs end end), 2) "乙班炼钢库存" , round(sum(case st.c_type when 107 then case st.p_type when 103 then st.ins - st.outs end end), 2) "乙班连铸库存" , round(sum(case st.c_type when 107 then case st.p_type when 104 then st.ins - st.outs end end), 2) "乙班炉卷库存" , round(sum(case st.c_type when 107 then case st.p_type when 105 then st.ins - st.outs end end), 2) "乙班热连库存" , round(sum(case st.c_type when 108 then case st.p_type when 102 then st.ins - st.outs end end), 2) "丙班炼钢库存" , round(sum(case st.c_type when 108 then case st.p_type when 103 then st.ins - st.outs end end), 2) "丙班连铸库存" , round(sum(case st.c_type when 108 then case st.p_type when 104 then st.ins - st.outs end end), 2) "丙班炉卷库存" , round(sum(case st.c_type when 108 then case st.p_type when 105 then st.ins - st.outs end end), 2) "丙班热连库存" , round(sum(case st.c_type when 109 then case st.p_type when 102 then st.ins - st.outs end end), 2) "丁班炼钢库存" , round(sum(case st.c_type when 109 then case st.p_type when 103 then st.ins - st.outs end end), 2) "丁班连铸库存" , round(sum(case st.c_type when 109 then case st.p_type when 104 then st.ins - st.outs end end), 2) "丁班炉卷库存" , round(sum(case st.c_type when 109 then case st.p_type when 105 then st.ins - st.outs end end), 2) "丁班热连库存" from t_stock st group by st.date order by st.date ); 


    最新回复(0)