oracle case when then 用法

SELECT
       D.DEPT_CODE,
       SUM(T.GATHER_ZONE_PLAN_NUM),
       SUM(T.ZONE_PLAN_NUM),
       SUM(T.GATHER_ZONE_ACTUAL_NUM),
       SUM(T.ZONE_ACTUAL_NUM),
       SUM(T.MISS_LOAD_BILL_NUM),
       SUM(T.SURPLUS_DEPART_NUM),
       SUM(T.NOT_DEPART_NUM),
       SUM(T.LATE_NESS_DEPART_NUM),
       SUM(CASE WHEN TRUNC(TO_NUMBER(T.ACTUAL_END_TM-T.PLAN_END_TM)*1440)<=? then 1 WHEN T.ACTUAL_END_TM IS NULL THEN 1 ELSE 0 END) AS BEFORE,
       SUM(CASE WHEN TRUNC(TO_NUMBER(T.ACTUAL_END_TM-T.PLAN_END_TM)*1440)>?  then 1 ELSE 0 END) AS LATE,
       TRUNC(AVG(CASE WHEN T.ACTUAL_END_TM IS NOT NULL THEN TO_NUMBER(T.PLAN_END_TM - T.PLAN_BEGIN_TM) * 1440 ELSE NULL END)) AS PLANCOST,
       TRUNC(AVG(TO_NUMBER(T.ACTUAL_END_TM-T.PLAN_BEGIN_TM)*1440))AS ACTUALCOST
     FROM TT_PICKUP_DEPOT_BATCH_SHOW T, TM_DEPARTMENT D
   WHERE T.ZONE_CODE = D.DEPT_CODE

你可能感兴趣的:(oracle case when then 用法)