我试图在更新声明中加入三个表,但到目前为止我还没有成功.我知道这个查询适用于连接两个表:
update table 1
set x = X * Y
from table 1 as t1 join table 2 as t2 on t1.column1 = t2.column1
Run Code Online (Sandbox Code Playgroud)
但是,就我而言,我需要加入三个表:
update table 1
set x = X * Y
from table 1 as t1 join table 2 as t2 join table3 as t3
on t1.column1 = t2.column1 and t2.cloumn2 = t3.column1
Run Code Online (Sandbox Code Playgroud)
不管用.我也尝试了以下查询:
update table 1
set x = X * Y
from table 1, table 2, table 3
where column1 = column2 and column2= column3
Run Code Online (Sandbox Code Playgroud)
有谁知道一种方法来实现这一目标?
Aar*_*and 16
你绝对不想使用table, table, table
语法; 这就是原因.至于你中间的代码示例,连接语法如下大致在相同的规则SELECT
,因为它确实为UPDATE
.JOIN t2 JOIN t3 ON ...
无效,但JOIN t2 ON ... JOIN t3 ON
有效.
所以这是我的建议,但应该更新以完全符合y
来自哪里:
UPDATE t1
SET x = x * y -- should either be t2.y or t3.y, not just y
FROM dbo.table1 AS t1
INNER JOIN table2 AS t2
ON t1.column1 = t2.column1
INNER JOIN table3 AS t3
ON t2.column2 = t3.column1;
Run Code Online (Sandbox Code Playgroud)