我在Orders表中添加了一个名为EventId的列,我必须为每行填充正确的值。
我想用更复杂的SQL查询来实现它,如下所示:
UPDATE [dbo].[Orders] o
SET o.EventId = ????
WHERE o.Id IN (SELECT o.id, s.eventid FROM orders o
INNER JOIN orderskudiscounts osd ON o.id = osd.orderid
INNER JOIN skus s ON osd.skuid = s.id GROUP BY o.id, s.eventid)
我不确定如何成功编写查询...我有超过2千个映射要做。所以我应该使用查询...
感谢您的帮助
答案 0 :(得分:3)
我猜你想要这样的更新:
UPDATE o
SET o.EventId = s.eventid
FROM orders o INNER JOIN
orderskudiscounts osd
ON o.id = osd.orderid INNER JOIN
skus s
ON osd.skuid = s.id;