MERGE INTO demo.a AS T1 USING demo.b AS T2 ON T1.id = T2.id WHEN MATCHED THEN UPDATE SET name = 'wf1' WHEN NOT MATCHED THEN INSERT VALUES(T2.id,T2.name); MERGE INTO demo.a AS T1 USING demo.b AS T2 ON T1.id = T2.id WHEN MATCHED AND sex='male' THEN UPDATE SET name = 'wf1' WHEN MATCHED AND sex='female' THEN UPDATE SET age = 10 WHEN NOT MATCHED AND age>10 THEN INSERT VALUES(T2.id,T2.name);