从 2 Table 更新查询
Update Query From 2 Table
我有以下 2 个表格:
表 1 是 tracsName,tracsid,N,NE...
表 2 是 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'
我有一个错误,如果你能给我逻辑或代码,那就太好了。
试试这个代码
UPDATE table1
SET table1.N = table2.n
FROM table2 WHERE name2 = name1
这是 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
我有以下 2 个表格:
表 1 是 tracsName,tracsid,N,NE...
表 2 是 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'
我有一个错误,如果你能给我逻辑或代码,那就太好了。
试试这个代码
UPDATE table1
SET table1.N = table2.n
FROM table2 WHERE name2 = name1
这是 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