我希望将两列的数据复制到另一个表中,该表有许多列,而且这两个表上都有一个公共列。
这是我的桌子:
ID = col1 \ col2
1- 13 - 12
2-8-3
3\x{e76f}7
1\x{e76f}0\x{e76f}0\x{e76f}0
2\x{e76f}0\x{e76f}\x{e76f}0
3\x{e76f}0\x{e76f}\x{e76f}
我尝试使用此question中的更新查询。
UPDATE table2 a,table1 b SET
a.col1 = b.col1,
a.col2 = b.col2,
a.col3 = a.col3 + b.col1,
a.col4 = a.col4 + b.col2
WHERE a.ID = b.ID但它给了
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'a'.不管怎样,这样做有可能吗?对不起,如果我没有以一种很好的方式编写表,但是堆栈溢出似乎不会创建表。
发布于 2014-06-21 18:56:25
您的语法在MySQL中看起来是正确的,但最好写成如下:
UPDATE table2 a join
table1 b
on a.ID = b.ID
SET a.col1 = b.col1,
a.col2 = b.col2,
a.col3 = a.col3 + b.col1,
a.col4 = a.col4 + b.col2;对于Server,语法是:
UPDATE a
SET col1 = b.col1,
col2 = b.col2,
col3 = a.col3 + b.col1,
col4 = a.col4 + b.col2
FROM table2 a join
table1 b
on a.ID = b.ID;Server中的错误可能是表后的别名上的错误,也可能是set语句中的set上的错误。
https://stackoverflow.com/questions/24344824
复制相似问题