我有以下2个表:
table1是tracsName,tracsid,N,NE...
table2是Tracs,kode,N2...
。我想用这个代码用N2值改变N值,N和更多是风箭头
更新查询,可以更简单吗?
UPDATE table1
SET
N=(select N2 from table2 where tracs='daraname2' AND kode='1-6'),
NE=(select NE2 from table2 where tracs='daraname2' AND kode='1-6'),
E=(select E2 from table2 where tracs='daraname2' AND kode='1-6'),
SE=(select SE2 from table2 where tracs='daraname2' AND kode='1-6'),
S=(select S2 from table2 where tracs='daraname2' AND kode='1-6'),
SW=(select SW2 from table2 where tracs='daraname2' AND kode='1-6'),
W=(select W2 from table2 where tracs='daraname2' AND kode='1-6'),
NW=(select NW2 from table2 where tracs='daraname2' AND kode='1-6')
WHERE tracsName='daraname2' AND tracsid='1-6'
我有错误,如果你能给我逻辑或代码,那就太棒了。
答案 0 :(得分:1)
试试这段代码
UPDATE table1
SET table1.N = table2.n
FROM table2 WHERE name2 = name1
答案 1 :(得分:1)
以下是mysql
的一般语法:
UPDATE TABLE1 a
JOIN TABLE2 b ON a.name1 = b.name2
SET a.n1 = b.n2
以下是sql server
的示例:
UPDATE a
SET n1 = b.n2
FROM TABLE1 a
JOIN TABLE2 b ON a.name1 = b.name2