Access 问题:构建报告时未获得所需的输出
我在 Access 中创建了一个报告,并编写了一个查询来从中获取记录 多个表如下:
SELECT BuildingDetails.*, Contractors.Item, ActionDetails.ActionType
FROM Contractors
INNER JOIN (BuildingDetails
INNER JOIN (ActionDetails
INNER JOIN DormData ON ActionDetails.ActionID = DormData.ActionID)
ON BuildingDetails.BuildingID = DormData.BuildingID)
ON Contractors.ID = DormData.ItemID;
现在我想要的只是通过查询检索 actiontype=repair
或 actionid=1
。我们有两个actontype“修复”和“替换”。
I have created a report in Access and I have written a query for fetching records from
multiple tables as follows:
SELECT BuildingDetails.*, Contractors.Item, ActionDetails.ActionType
FROM Contractors
INNER JOIN (BuildingDetails
INNER JOIN (ActionDetails
INNER JOIN DormData ON ActionDetails.ActionID = DormData.ActionID)
ON BuildingDetails.BuildingID = DormData.BuildingID)
ON Contractors.ID = DormData.ItemID;
Now what I want is only actiontype=repair
or actionid=1
get retrieved by the query. We have two actontype
"repair" and "replace".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我对您的查询进行了一些重新格式化以使其整洁。您还没有指定过滤器的数据是什么样的,但根据您所说的,我会采用类似以下内容的内容
如果 ActionID 是一个将 ActionID(1) 与 ActionType ('Repair') 相关联的查找列,那么您就不需要不需要 or 并且可以坚持 WHERE 子句中的一个或另一个条件。
希望这有帮助。
I have reformatted you query a little to neaten it up. You haven't specified what the data looks like for the filter but based on what you have said I would go with something like the following
If ActionID is a lookup column that relates ActionID(1) to ActionType ('Repair') then you don't need the or and can stick to one or other of the conditions in the WHERE Clause.
Hope this helps.
我怀疑您只需要使用
actiontype = 'repair'
进行过滤(我进一步猜测ActionID
是一个自动编号,并且您有一行{ActionID = 1, actiontype = 'repair'}
只是偶然...但这可能推断得太远了:)我很惊讶@David Steele的答案在Access(ACE,Jet,等等)中有效,因为他从
JOIN
子句(但是,如果确实如此——建议使用链接表——那么您应该“接受”该答案)。但我也可以抵制“整理它们”,以便ON
子句靠近表名称:I suspect you only need to filter using
actiontype = 'repair'
(I further guess thatActionID
is an autonumber and you have a row{ActionID = 1, actiontype = 'repair'}
only by chance... but this is maybe extrapolating too far :)I'm surprised @David Steele's answer works in Access (ACE, Jet, whatever) because he's removed the parentheses from the
JOIN
clauses (however if it does -- suggesting a linked table -- then you should "accept" that answer). But I too could resist 'neatening them up' so that theON
clauses are close to the table names:将其添加到 select 语句的末尾以解决问题:
Add this to the end of your select statement to fix the issue: