Which God help me to write the SQL

The following is selection logic, I can't write, who can help me:
TABLE_A to TABLE_B mapping
Selection Criteria:
Select all from records from TABLE_A with max AS_OF_DATE and get the list of distinct PARENT_NUMBER with their KNE_NO's.Match the PARENT_NUMBER with TABLE_B.PARENT_ACCOUNT_NO and SOURCE_SYSTEM_ID = TABLE_B.SOURCE_SYSTEM_ID .If match found then update with the following mapping

If a record in SSB_PARENT_ACCOUNT for PARENT_ACCOUNT_NO and SOURCE_SYSTEM_ID, does not find a match with the PARENT_NUMBER and SOURCE_SYSTEM , data from Selection criteria and also with GMBH_CUSTOMER_REF. PARENT_NUMBER then delete the record from SSB_PARENT_ACCOUNT

Started by Fitch at November 20, 2016 - 5:43 PM

Not a standard merge.

Posted by Antonio at November 28, 2016 - 5:55 PM

The birds are not pass. Haha MERGE function, cases:
MERGE INTO products p
USING newproducts np
ON (p.product_id = np.product_id)
WHEN MATCHED THEN
UPDATE
SET p.product_name = np.product_name,
p.category = np.category
DELETE WHERE (p.category = 'ELECTRNCS')
WHEN NOT MATCHED THEN
INSERT
VALUES (np.product_id, np.product_name, np.category) ;

Posted by Craig at November 30, 2016 - 6:50 PM