Oracle
 sql >> Teknologi Basis Data >  >> RDS >> Oracle

Perbarui beberapa kolom berdasarkan perhitungan persentase bijaksana di Oracle

ok, jadi akhirnya setelah banyak klarifikasi, sepertinya seharusnya:

+perbarui:duplikat

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. Database Oracle TNS Panjang nilai untuk 'sumber data' kunci melebihi batas '128'

  2. SQL Oracle Menghitung Cluster

  3. Bagaimana cara menghapus duplikat dari daftar yang dipisahkan koma dengan regex di Oracle tetapi saya tidak ingin nilai duplikat?

  4. Oracle Mengonversi Baris ke Kolom

  5. Bisakah kita menentukan derajat paralelisme secara dinamis?