学习Oracle日记(八)--ORACLE CASE WHEN

系统 1564 0

Ⅰ. ORACLE  WHERE 字句里面使用CASE WHEN 25行

Ⅱ.  嵌套使用 CASE WHEN  2~13行

      
         1
      
      
        SELECT
      
      
         2
      
      
        SUM
      
      (
      
        CASE
      
      
        WHEN
      
       M.MV_AVG 
      
        <
      
      
        800
      
      
        AND
      
       C.THICKNESS 
      
        >=
      
      
        0.5
      
      
        AND
      
       C.THICKNESS 
      
        <=
      
      
        0.9
      
      
        THEN
      
        (
      
        CASE
      
      
        WHEN
      
       D.MV_AVG 
      
        =
      
      
        0
      
      
        OR
      
       D.MV_AVG 
      
        IS
      
      
        NULL
      
      
        THEN
      
      
        0
      
      
        ELSE
      
       P.LENGTH 
      
        /
      
       D.MV_AVG 
      
        END
      
       ) 
      
        END
      
       ) R1CD ,
      
        --
      
      
        1区间内长度/炉区速度
      
      
         3
      
      
        SUM
      
      (
      
        CASE
      
      
        WHEN
      
       M.MV_AVG 
      
        <
      
      
        800
      
      
        AND
      
       C.THICKNESS 
      
        >
      
      
        0.9
      
      
        AND
      
       C.THICKNESS 
      
        <=
      
      
        1.3
      
      
        THEN
      
        (
      
        CASE
      
      
        WHEN
      
       D.MV_AVG 
      
        =
      
      
        0
      
      
        OR
      
       D.MV_AVG 
      
        IS
      
      
        NULL
      
      
        THEN
      
      
        0
      
      
        ELSE
      
       P.LENGTH 
      
        /
      
       D.MV_AVG 
      
        END
      
      ) 
      
        END
      
       ) R2CD ,
      
        --
      
      
        2区间内长度/炉区速度
      
      
         4
      
      
        SUM
      
      (
      
        CASE
      
      
        WHEN
      
       M.MV_AVG 
      
        <
      
      
        800
      
      
        AND
      
       C.THICKNESS 
      
        >
      
      
        1.3
      
      
        AND
      
       C.THICKNESS 
      
        <=
      
      
        1.6
      
      
        THEN
      
        (
      
        CASE
      
      
        WHEN
      
       D.MV_AVG 
      
        =
      
      
        0
      
      
        OR
      
       D.MV_AVG 
      
        IS
      
      
        NULL
      
      
        THEN
      
      
        0
      
      
        ELSE
      
       P.LENGTH 
      
        /
      
       D.MV_AVG 
      
        END
      
      ) 
      
        END
      
       ) R3CD ,
      
        --
      
      
        3区间内长度/炉区速度
      
      
         5
      
      
        SUM
      
      (
      
        CASE
      
      
        WHEN
      
       M.MV_AVG 
      
        <
      
      
        800
      
      
        AND
      
       C.THICKNESS 
      
        >
      
      
        1.6
      
      
        THEN
      
        (
      
        CASE
      
      
        WHEN
      
       D.MV_AVG 
      
        =
      
      
        0
      
      
        OR
      
       D.MV_AVG 
      
        IS
      
      
        NULL
      
      
        THEN
      
      
        0
      
      
        ELSE
      
       P.LENGTH 
      
        /
      
       D.MV_AVG 
      
        END
      
      ) 
      
        END
      
       ) R4CD ,   
      
        --
      
      
        4区间内长度/炉区速度
      
      
         6
      
      
        SUM
      
      (
      
        CASE
      
      
        WHEN
      
       M.MV_AVG 
      
        >=
      
      
        800
      
      
        AND
      
       M.MV_AVG 
      
        <
      
      
        830
      
      
        AND
      
       C.THICKNESS 
      
        >=
      
      
        0.5
      
      
        AND
      
       C.THICKNESS 
      
        <=
      
      
        0.9
      
      
        THEN
      
         (
      
        CASE
      
      
        WHEN
      
       D.MV_AVG 
      
        =
      
      
        0
      
      
        OR
      
       D.MV_AVG 
      
        IS
      
      
        NULL
      
      
        THEN
      
      
        0
      
      
        ELSE
      
       P.LENGTH 
      
        /
      
       D.MV_AVG 
      
        END
      
      ) 
      
        END
      
       ) R5CD ,
      
        --
      
      
        5区间内长度/炉区速度
      
      
         7
      
      
        SUM
      
      (
      
        CASE
      
      
        WHEN
      
       M.MV_AVG 
      
        >=
      
      
        800
      
      
        AND
      
       M.MV_AVG 
      
        <
      
      
        830
      
      
        AND
      
       C.THICKNESS 
      
        >
      
      
        0.9
      
      
        AND
      
       C.THICKNESS 
      
        <=
      
      
        1.3
      
      
        THEN
      
        (
      
        CASE
      
      
        WHEN
      
       D.MV_AVG 
      
        =
      
      
        0
      
      
        OR
      
       D.MV_AVG 
      
        IS
      
      
        NULL
      
      
        THEN
      
      
        0
      
      
        ELSE
      
       P.LENGTH 
      
        /
      
       D.MV_AVG 
      
        END
      
      ) 
      
        END
      
       ) R6CD ,
      
        --
      
      
        6区间内长度/炉区速度
      
      
         8
      
      
        SUM
      
      (
      
        CASE
      
      
        WHEN
      
       M.MV_AVG 
      
        >=
      
      
        800
      
      
        AND
      
       M.MV_AVG 
      
        <
      
      
        830
      
      
        AND
      
       C.THICKNESS 
      
        >
      
      
        1.3
      
      
        AND
      
       C.THICKNESS 
      
        <=
      
      
        1.6
      
      
        THEN
      
        (
      
        CASE
      
      
        WHEN
      
       D.MV_AVG 
      
        =
      
      
        0
      
      
        OR
      
       D.MV_AVG 
      
        IS
      
      
        NULL
      
      
        THEN
      
      
        0
      
      
        ELSE
      
       P.LENGTH 
      
        /
      
       D.MV_AVG 
      
        END
      
      ) 
      
        END
      
       ) R7CD ,
      
        --
      
      
        7区间内长度/炉区速度
      
      
         9
      
      
        SUM
      
      (
      
        CASE
      
      
        WHEN
      
       M.MV_AVG 
      
        >=
      
      
        800
      
      
        AND
      
       M.MV_AVG 
      
        <
      
      
        830
      
      
        AND
      
       C.THICKNESS 
      
        >
      
      
        1.6
      
      
        THEN
      
       (
      
        CASE
      
      
        WHEN
      
       D.MV_AVG 
      
        =
      
      
        0
      
      
        OR
      
       D.MV_AVG 
      
        IS
      
      
        NULL
      
      
        THEN
      
      
        0
      
      
        ELSE
      
       P.LENGTH 
      
        /
      
       D.MV_AVG 
      
        END
      
      ) 
      
        END
      
       ) R8CD ,   
      
        --
      
      
        8区间内长度/炉区速度
      
      
        10
      
      
        SUM
      
      (
      
        CASE
      
      
        WHEN
      
       M.MV_AVG 
      
        >=
      
      
        830
      
      
        AND
      
       C.THICKNESS 
      
        >=
      
      
        0.5
      
      
        AND
      
       C.THICKNESS 
      
        <=
      
      
        0.9
      
      
        THEN
      
        (
      
        CASE
      
      
        WHEN
      
       D.MV_AVG 
      
        =
      
      
        0
      
      
        OR
      
       D.MV_AVG 
      
        IS
      
      
        NULL
      
      
        THEN
      
      
        0
      
      
        ELSE
      
       P.LENGTH 
      
        /
      
       D.MV_AVG 
      
        END
      
      ) 
      
        END
      
       ) R9CD ,
      
        --
      
      
        9区间内长度/炉区速度
      
      
        11
      
      
        SUM
      
      (
      
        CASE
      
      
        WHEN
      
       M.MV_AVG 
      
        >=
      
      
        830
      
      
        AND
      
       C.THICKNESS 
      
        >
      
      
        0.9
      
      
        AND
      
       C.THICKNESS 
      
        <=
      
      
        1.3
      
      
        THEN
      
        (
      
        CASE
      
      
        WHEN
      
       D.MV_AVG 
      
        =
      
      
        0
      
      
        OR
      
       D.MV_AVG 
      
        IS
      
      
        NULL
      
      
        THEN
      
      
        0
      
      
        ELSE
      
       P.LENGTH 
      
        /
      
       D.MV_AVG 
      
        END
      
      ) 
      
        END
      
       ) R10CD ,
      
        --
      
      
        10区间内长度/炉区速度
      
      
        12
      
      
        SUM
      
      (
      
        CASE
      
      
        WHEN
      
       M.MV_AVG 
      
        >=
      
      
        830
      
      
        AND
      
       C.THICKNESS 
      
        >
      
      
        1.3
      
      
        AND
      
       C.THICKNESS 
      
        <=
      
      
        1.6
      
      
        THEN
      
         (
      
        CASE
      
      
        WHEN
      
       D.MV_AVG 
      
        =
      
      
        0
      
      
        OR
      
       D.MV_AVG 
      
        IS
      
      
        NULL
      
      
        THEN
      
      
        0
      
      
        ELSE
      
       P.LENGTH 
      
        /
      
       D.MV_AVG 
      
        END
      
      ) 
      
        END
      
       ) R11CD ,
      
        --
      
      
        11区间内长度/炉区速度
      
      
        13
      
      
        SUM
      
      (
      
        CASE
      
      
        WHEN
      
       M.MV_AVG 
      
        >=
      
      
        830
      
      
        AND
      
       C.THICKNESS 
      
        >
      
      
        1.6
      
      
        THEN
      
        (
      
        CASE
      
      
        WHEN
      
       D.MV_AVG 
      
        =
      
      
        0
      
      
        OR
      
       D.MV_AVG 
      
        IS
      
      
        NULL
      
      
        THEN
      
      
        0
      
      
        ELSE
      
       P.LENGTH 
      
        /
      
       D.MV_AVG 
      
        END
      
      ) 
      
        END
      
       ) R12CD    
      
        --
      
      
        12区间内长度/炉区速度
      
      
        14
      
      
        FROM
      
       PRODCOIL_MV M , (
      
        SELECT
      
       M.PCOIL_SID , M.MV_AVG   
      
        FROM
      
       PRODCOIL_MV M  
      
        WHERE
      
       M.QDR_CHAN 
      
        =
      
      
        1
      
      
        AND
      
        M.PRODUCT_LINE 
      
        =
      
      
        '
      
      
        CGL1
      
      
        '
      
      
        ) D ,PRODCOILS P ,COILS  C  ,PRODCOILS_SOURCES S  


      
      
        15
      
      
        WHERE
      
       M.PCOIL_SID 
      
        =
      
      
         P.PCOIL_SID 


      
      
        16
      
      
        AND
      
       P.PCOIL_SID 
      
        =
      
      
         S.PCOIL_SID


      
      
        17
      
      
        AND
      
       S.COIL_SID 
      
        =
      
      
         C.COIL_SID 


      
      
        18
      
      
        AND
      
       M.PCOIL_SID 
      
        =
      
      
         D.PCOIL_SID


      
      
        19
      
      
        AND
      
       P.DUMMY_COIL 
      
        =
      
      
        0
      
      
        20
      
      
        AND
      
       M.PRODUCT_LINE 
      
        =
      
      
        '
      
      
        CGL1
      
      
        '
      
      
        21
      
      
        AND
      
       P.PRODUCT_LINE 
      
        =
      
      
        '
      
      
        CGL1
      
      
        '
      
      
        22
      
      
        AND
      
       C.PRODUCT_LINE 
      
        =
      
      
        '
      
      
        CGL1
      
      
        '
      
      
        23
      
      
        AND
      
       S.PRODUCT_LINE 
      
        =
      
      
        '
      
      
        CGL1
      
      
        '
      
      
        24
      
      
        25
      
      
        AND
      
       M.QDR_CHAN 
      
        =
      
       (
      
        CASE
      
      
        WHEN
      
      
        '
      
      
        CGL1
      
      
        '
      
      
        =
      
      
        '
      
      
        CGL1
      
      
        '
      
      
        THEN
      
      
        521
      
      
        ELSE
      
      
        531
      
      
        END
      
      
         )


      
      
        26
      
      
        AND
      
       P.PROD_DAY  
      
        BETWEEN
      
       TO_DATE(
      
        '
      
      
        2014-12-01
      
      
        '
      
      ,
      
        '
      
      
        YYYY-MM-DD
      
      
        '
      
      ) 
      
        AND
      
       TO_DATE(
      
        '
      
      
        2014-12-31
      
      
        '
      
      ,
      
        '
      
      
        YYYY-MM-DD
      
      
        '
      
      )
    

 

学习Oracle日记(八)--ORACLE CASE WHEN


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论