您可以使用两个表的并集来执行此操作,然后为已存在的ID选择更新的记录,例如
with union_table as ( select *, 0 as new_flag from t1 union all select *, 1 as new_flag from t2 ), stage_table as ( select *, max(new_flag) over (partition by id) as max_flag from union_table ), stage_table2 as ( select id, name, new_flag from stage_table where new_flag = max_flag ) select id, name from stage_table2
窗 max 将帮助您确定是否需要使用更新的值替换特定的ID
max