我想根据另一个表的值更新表中的列,我使用稍旧版本的 Firebird 2.1,因此它在更新执行期间不支持 join 语句。为了消除这种情况,根据原始 Firebird 常见问题解答中给出的说明http://www.firebirdfaq.org/faq323/以下语句应该有效,但它会丢失一些值以及返回为 null 的列的值,如下面的数据集表格形式所示。
例如,Elements 表中的 Num 21 的 END_I 列中的值应为 23,因为它与节点表具有完全相同的 X_I、Y_I 和 Z_I 值,但上述语句返回 null 。
update elements E set E.END_I = (select n.node_num from nodes N
where (N.XI =E.X_I and N.YI = E.Y_I and N.ZI=E.Z_I) )
where exists (select 1 from nodes N where (N.XI =E.X_I and N.YI = E.Y_I and N.ZI=E.Z_I))
ELEMENTS
Num End_I End_J X_I Y_I Z_I
17 18.000000 19.000000 0.000000 1.500000 18.000000 0.000000 1.500000 21.000000
18 19.000000 20.000000 0.000000 1.500000 21.000000 0.000000 1.500000 24.000000
19 20.000000 21.000000 0.000000 1.500000 24.000000 0.000000 1.500000 27.000000
20 21.000000 22.000000 0.000000 1.500000 27.000000 0.000000 1.500000 30.000000
21 [null] 24.000000 2.400000 0.000000 0.000000 2.400000 0.000000 3.000000
22 [null] 25.000000 2.400000 0.000000 3.000000 2.400000 0.000000 6.000000
23 [null] 26.000000 2.400000 0.000000 6.000000 2.400000 0.000000 9.000000
NODES
Node_Num XI YI ZI
20 0.000000 1.500000 24.000000
21 0.000000 1.500000 27.000000
22 0.000000 1.500000 30.000000
23 2.400000 0.000000 0.000000
24 2.400000 0.000000 3.000000
25 2.400000 0.000000 6.000000
而不是尝试使用UPDATE
, use MERGE:
merge into elements E
using node N
on N.XI = E.X_I and N.YI = E.Y_I and N.ZI = E.Z_I
when matched then
update set E.END_I = N.node_num
合并允许您使用另一个表、视图或查询作为数据源来更新或插入到表中。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)