PL/SQL Merge statement for data update

MERGE into Product_Sales  a

USING( SELECT distinct cusip,thirtydayaverage
        FROM vw_daily_volume
        WHERE vw_daily_volume.cusip in ( select distinct cusip from Product_Sales
                                              where process_date =( SELECT MAX(PROCESS_DATE) FROM Product_Sales)
                                             )
          AND created_ts = (select max(created_ts) from vw_daily_volume)
     )t1 
  ON (
      a.cusip = t1.cusip and
       a.process_date = (SELECT MAX(PROCESS_DATE) FROM Product_Sales)
  )
  WHEN matched then
  UPDATE set a.average_daily_volume = NVL(a.average_daily_volume,t1.thirtydayaverage);

Leave a Reply

Your email address will not be published. Required fields are marked *