[英]How can I use insert with select from other table in a merge statement?
I have this query.我有这个查询。
MERGE sales.category t
USING sales.category_staging s
ON (s.category_id = t.category_id)
WHEN MATCHED
THEN UPDATE SET
t.category_name = s.category_name,
t.amount = s.amount
WHEN NOT MATCHED BY TARGET
THEN INSERT t(category_id, category_name, amount)
VALUES select s.category_id, s.category_name, s.amount from s
WHEN NOT MATCHED BY SOURCE
THEN DELETE;
How can I use insert with select from other table in a merge statement?如何在合并语句中使用来自其他表的 select 插入?
You wouldn't.你不会的。 You have already defined
S
so you can reference those columns in the VALUES
clause.您已经定义了
S
,因此您可以在VALUES
子句中引用这些列。 You also don't put the alias of the destination table prior to the destination columns:您也不要将目标表的别名放在目标列之前:
THEN INSERT (category_id, category_name, amount)
VALUES (s.category_id, s.category_name, s.amount)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.