如果我有这三个表(只是为了学习 UNION 的一个例子,这些不是真正的表):
表格及其列:
Customer:
id | name | order_status
Order_Web:
id | customer_id | order_filled
Order:
id | customer_id | order_filled
当使用 Union 为该客户填写 Order_Web 表或 Order 表时,我想更新 Customer 表中的 order_status:
UPDATE c
SET c.order_status = 1
FROM Customer AS c
INNER JOIN Order_Web As ow
ON c.id = ow.customer_id
WHERE ow.order_filled = 1
UPDATE c
SET c.order_status = 1
FROM Customer AS c
INNER JOIN Order As o
ON c.id = o.customer_id
WHERE o.order_filled = 1
如何使用 order_web 和 order 上的 Union 组合这两个更新?
使用 Microsoft SQL Server Management Studio