【发布时间】:2019-04-11 02:53:17
【问题描述】:
在我正在处理的场景中,我需要一些帮助。
我有两个表 Product_Staging 和 Product。表格内容如下。
Product_Staging:
Account_No Product_No Cur_Revenue Prev_Revenue
12 AB 5.0 3.0
13 BC 4.0 4.0
15 DF 10.0 7.5
产品:
Account_No Product_No Cur_Revenue Prev_Revenue
12 AB 1.0 3.0
13 BC 4.0 5.0
16 DF 10.0 17.5
17 CG 5.0 6.0
当 Account_No 和 Product_No 匹配时,我需要使用 Product_Staging 表中的内容更新 Product 表的 Cur_Revenue 和 Prev_Revenue 字段,否则清除 Product 表中的值。示例输出如下。
更新后的产品:
Account_No Product_No Cur_Revenue Prev_Revenue
12 AB 5.0 3.0 (Updated from Product_Staging)
13 BC 4.0 4.0 (Updated from Product_Staging)
16 DF (Cleared)
17 CG (Cleared)
Product_Staging 中的第 15 行/DF 将被丢弃,因为它在 Product 表中不存在。
有人可以帮忙吗?
【问题讨论】:
标签: sql sql-server sql-server-2008 sql-update