Oracle
 sql >> база данни >  >> RDS >> Oracle

Актуализирайте множество колони въз основа на процентно изчисление в Oracle

добре, така че най-накрая след тонове разяснения, изглежда, че трябва да бъде:

+актуализация:дубликати

merge into TBL_FIBER_INV_SIGN_OFF_SHEET DST
using (
   -- Source: original query
   with mv as (
       select * from (
          select
             circle, 
             regexp_substr(MP,'[^/]+',1,1)MAINTENANCE_ZONE_NAME,
             regexp_substr(MP,'[^/]+',1,2)MAINTENANCE_ZONE_CODE,
             SPAN_TYPE,
             SPAN_LINK_ID,
             NE_LENGTH, -- ? NE_LENGTH - 1
             ROUTE_APPROVED_BY_CMM as CMM_APPROVED_LENGTH,
             row_number()over(partition by SPAN_LINK_ID order by ROUTE_APPROVED_BY_CMM) rn
          from TBL_FIBER_INV_CMP_REPORT_MV    
          where CMM_APPROVED_DATE IS NOT NULL 
             OR ROUTE_APPROVED_BY_CMM > 0 
             OR JOB_PROGRESS_FLAG = 1
       )
       where rn=1
   )
   ,pct as (
       SELECT 
          ROUND(SUM(NVL(CALCULATED_LENGTH,0)/1000),4) AS NE_LENGTH -- ? NE_LENGTH - 2
         ,ROUND(SUM(CASE WHEN RJ_CONSTRUCTION_METHODOLOGY NOT LIKE '%AERIAL%' 
                         OR RJ_CONSTRUCTION_METHODOLOGY IS NULL 
                         THEN NVL(CALCULATED_LENGTH,0) 
                         ELSE 0 
                    END)/1000,4
               ) AS UG_LENGTH
         ,ROUND(SUM(CASE WHEN RJ_CONSTRUCTION_METHODOLOGY LIKE '%AERIAL%' 
                         THEN NVL(CALCULATED_LENGTH,0) 
                         ELSE 0 
                    END)/1000,4
               ) AS AR_LENGTH
          FROM [email protected]_LINK_NE_VIEWER
   )
   select 
      mv.*
     --,cpt.*
     ,case when mv.CMM_APPROVED_LENGTH > pct.NE_LENGTH then 0.8 * pct.UG_length
           when mv.CMM_APPROVED_LENGTH = pct.NE_LENGTH then 0.9 * pct.UG_length
      end as FSA_UG
     ,case when mv.CMM_APPROVED_LENGTH > pct.NE_LENGTH then 0.2 * pct.AR_LENGTH
           when mv.CMM_APPROVED_LENGTH = pct.NE_LENGTH then 0.1 * pct.AR_LENGTH
      end as FSA_AERIAL
   from mv, pct
   -- end of Source query
) SRC
on ( dst.SPAN_LINK_ID =  src.SPAN_LINK_ID )
when matched then update
   set FSA_UG = src.FSA_UG
      ,FSA_AERIAL = src.FSA_AERIAL;


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. TNS-12519 без максимален достигнат процес

  2. наистина прост SQL Не е израз GROUP BY - Oracle

  3. Извикване на функция от DLL (c#) в Oracle Forms

  4. Синтактична грешка. Липсваща ключова дума в оператора case в клаузата WHERE

  5. Получаване на списък с всички таблици в Oracle?