http://imageshack.us/photo/my-images/839/noeuds.jpg/
刚添加了真实表格的链接。 Noeud 116可以通过INSEE_COM更新117的信息。(116与117记录中的N_AMONT相关)
我有这张桌子(noueds):
NOEUD TYPE_MAT N_AMONT LONG_CABLE ADDRESS
123 REP 100 12 abc
130 AMP 229 12
173 PPP 130 1 AAA
我想写一个UPDATE查询来填充NODES.LONG_CABLE = 1之后的节点的所有数据ADDRESS。
例如:
我搜索了所有LONG_CABLE = 1的节点,给了我noeud 173;那么130之前的节点应该具有相同的地址173。
我可以搜索所有将更新的节点:
SELECT *
FROM noeuds AS tab,
[SELECT noeuds.* FROM noeuds WHERE (((noeuds.LONG_CABLE)=" 1"))]. AS a1
WHERE (((tab.NOEUD)=([a1].[n_amont])) AND ((tab.ADDRESS)=" "));
我正在使用MS Access。
编辑:
仅更新为1m calbe选择的记录。有没有人知道如何更新noeuds.n_amont指出的那些不在选定的表中,而是在原来的noeuds上?
答案 0 :(得分:1)
我将此作为两个查询提供,以便您可以查看第一个是否返回正确的地址和代码组合以进行更新。
<强> FirstQ 强>
SELECT n.NOEUD, n.ADDRESS,
(SELECT TOP 1 Noeud
FROM Noeuds WHERE Noeud<n.Noeud
ORDER BY Noeud DESC) AS CodeToUpdate
FROM noeuds AS n
WHERE n.LONG_CABLE="1"
ORDER BY n.NOEUD
<强>更新强>
UPDATE noeuds
INNER JOIN FirstQ
ON noeuds.NOEUD = FirstQ.CodeToUpdate
SET noeuds.ADDRESS = [FirstQ].[ADDRESS]</s>
编辑重新评论
SELECT a.noeud,
a.long_cable,
a.address,
noeuds_1.n_amont,
noeuds_1.address
FROM (SELECT *
FROM noeuds
WHERE long_cable = '1') AS a
INNER JOIN noeuds AS noeuds_1
ON a.n_amont = noeuds_1.noeud;
更新#2
UPDATE (SELECT n_amont,
address
FROM noeuds
WHERE long_cable = '1') AS a
INNER JOIN noeuds AS n
ON a.n_amont = n.noeud
SET n.address = a.Address
WHERE n.address IS NULL
答案 1 :(得分:0)
鉴于那个
您可以执行以下操作(但不确定它是否适用于访问):
UPDATE TableName
SET spalteA = t2.SpalteB
FROM TableName AS t1
INNER JOIN TableName AS t2
ON t2.node = t1.node - 1
WHERE t1.node > 1