我正在使用MS Access 2013.我的数据库有四个相关表:
Table A) Numerical_Key_A, {Other Data Items}
Table B) Numerical_Key_B, "Adjustment Value", {Other Data Items}
Table C) Numerical_Key_C, {Other Data Items}
Table D) {Other Data Items}, Link-to-B, Link-to-A, Link-to-C
然而,它的工作方式是,进入表D记录的Link-to-C始终与Numbers_Key_A完全一致“调整值”。因此,当我输入Link-to-A和Link-to-B时,我想自动计算Link-to-C。
据我所知,这将需要表D具有计算字段,该字段从链接表B获取其数据,Access不允许。还有另一种方法吗?如果可能的话,我宁愿不使用VBA,但如果这是唯一的方法,我只需要学习如何做到这一点。 (我知道VBA for Excel,但之前从未在Access中使用过它。)
答案 0 :(得分:0)
如果我理解得很好,您需要做的就是在表之间创建连接,例如:
SELECT D.Field1, D.Field2, B.[Adjustment Value]
FROM Table_D AS D INNER JOIN Table_B AS B ON D.Link-To-B = B.Numerical_Key_B
如需了解更多信息,请参阅:
Join tables and queries
How to: Perform Joins Using Access SQL
<强> [编辑] 强>
在表D中,有一个字段,我在上面的snippit中标记为“Link-to-C”。此字段应使用Link-to-A和TableB.AdjustmentValue
的值填充SELECT D.Field1, D.Link-To-C + D.Link-To-A + B.[Adjustment Value] AS CalculatedField
FROM (Table_D AS D INNER JOIN Table_B AS B ON D.Link-To-B = B.Numerical_Key_B)
INNER JOIN Table_C AS C ON C.Numerical_Key_C = D.Link-To-C)
INNER JOIN Table_A AS A ON A.Numerical_Key_A = D.Link-To-A
注意:我没有机会测试它。这只是一个想法。
最后我需要提醒您:在使用多个连接时,访问类似于() / bracket /。
<强> [EDIT2] 强>
根据讨论,下面的查询应返回计算字段:
SELECT C.MetaLevel, R.LevelAdjustment, C.MetaLevel+ R.LevelAdjustment AS NominalLevel
FROM tblRank AS R INNER JOIN tblCreatures AS C ON R.ID = C.Rank;
如果您想在 tblCreatures 中更新 NominalLevel ,请使用以下查询:
UPDATE tblCreatures AS C
INNER JOIN tblRank AS R ON R.ID = C.Rank
SET C.NominalLevel = (C.MetaLevel+ R.LevelAdjustment);
NominalLevel 已更新。你也可以选择它......
SELECT C.MetaLevel, R.LevelAdjustment, C.NominalLevel
FROM tblRank AS R INNER JOIN tblCreatures AS C ON R.ID = C.Rank;
干杯,
马切伊