MERGE INTO ARCHIVE_OSEARCH_WEBSERVICESEXECUTION_RABI_DAILY_TB d
   USING (
     SELECT
        -- PKs
        METADATA_REGION,
        SACTION,
        SRECORDTYPE,
        SACCOUNTTYPE,
        SCOMPID,
        STYPE,
        -- Timestamp aggregation
        TRUNC("TIMESTAMP") AS "TIMESTAMP",
        -- Summarized columns
        SUM(DOC_COUNT) AS DOC_COUNT,
        -- Top hits columns
        MAX(INDEX_) AS INDEX_,
        MAX(KINTEGRATIONAPPLICATIONDEF) AS KINTEGRATIONAPPLICATIONDEF,
        MAX(SAUTHENTICATIONMETHOD) AS SAUTHENTICATIONMETHOD,
        MAX(SINTEGRATIONAPPLICATIONNAME) AS SINTEGRATIONAPPLICATIONNAME,
        MAX(SDCID) AS SDCID,
        MAX(SAPIVERSION) AS SAPIVERSION,
        MAX(SSTATE) AS SSTATE,
        MAX(NRESPONSECODE) AS NRESPONSECODE,
        MAX(SSERVICETYPE) AS SSERVICETYPE,
        MAX(SINTEGRATIONAPPLICATIONID) AS SINTEGRATIONAPPLICATIONID,
        MAX(SINTEGRATIONAPPLICATIONSCRIPTID) AS SINTEGRATIONAPPLICATIONSCRIPTID
     FROM SRC_OSEARCH_WEBSERVICESEXECUTION_RABI_TB
     GROUP BY METADATA_REGION, SACTION, SRECORDTYPE, SACCOUNTTYPE, SCOMPID, STYPE, TRUNC("TIMESTAMP")
   ) src
   ON (
     d.METADATA_REGION = src.METADATA_REGION AND
     d.SACTION = src.SACTION AND
     d.SRECORDTYPE = src.SRECORDTYPE AND
     d.SACCOUNTTYPE = src.SACCOUNTTYPE AND
     d.SCOMPID = src.SCOMPID AND
     d.STYPE = src.STYPE AND
     d."TIMESTAMP" = src."TIMESTAMP"
   )
   WHEN MATCHED THEN
     UPDATE SET
       d.DOC_COUNT = d.DOC_COUNT + src.DOC_COUNT
   WHEN NOT MATCHED THEN
     INSERT (METADATA_REGION, SACTION, SRECORDTYPE, SACCOUNTTYPE, SCOMPID, STYPE, "TIMESTAMP", DOC_COUNT, INDEX_, KINTEGRATIONAPPLICATIONDEF, SAUTHENTICATIONMETHOD, SINTEGRATIONAPPLICATIONNAME, SDCID, SAPIVERSION, SSTATE, NRESPONSECODE, SSERVICETYPE, SINTEGRATIONAPPLICATIONID, SINTEGRATIONAPPLICATIONSCRIPTID)
     VALUES (src.METADATA_REGION, src.SACTION, src.SRECORDTYPE, src.SACCOUNTTYPE, src.SCOMPID, src.STYPE, src."TIMESTAMP", src.DOC_COUNT, src.INDEX_, src.KINTEGRATIONAPPLICATIONDEF, src.SAUTHENTICATIONMETHOD, src.SINTEGRATIONAPPLICATIONNAME, src.SDCID, src.SAPIVERSION, src.SSTATE, src.NRESPONSECODE, src.SSERVICETYPE, src.SINTEGRATIONAPPLICATIONID, src.SINTEGRATIONAPPLICATIONSCRIPTID);
