Access 问题:构建报告时未获得所需的输出

发布于 2024-11-06 00:03:54 字数 499 浏览 0 评论 0原文

我在 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=repairactionid=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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

涙—继续流 2024-11-13 00:03:54

我对您的查询进行了一些重新格式化以使其整洁。您还没有指定过滤器的数据是什么样的,但根据您所说的,我会采用类似以下内容的内容

SELECT BuildingDetails.*, 
Contractors.Item, 
ActionDetails.ActionType 
FROM Contractors 
INNER JOIN DormData ON Contractors.ID = DormData.ItemID
INNER JOIN ActionDetails ON DormData.ActionID = ActionDetails.ActionID
INNER JOIN BuildingDetails ON DormData.BuildingID = BuildingDetails.BuildingID
WHERE ActionDetails.ActionType = 'Repair' OR ActionID=1

如果 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

SELECT BuildingDetails.*, 
Contractors.Item, 
ActionDetails.ActionType 
FROM Contractors 
INNER JOIN DormData ON Contractors.ID = DormData.ItemID
INNER JOIN ActionDetails ON DormData.ActionID = ActionDetails.ActionID
INNER JOIN BuildingDetails ON DormData.BuildingID = BuildingDetails.BuildingID
WHERE ActionDetails.ActionType = 'Repair' OR ActionID=1

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.

流年里的时光 2024-11-13 00:03:54

我怀疑您只需要使用 actiontype = 'repair' 进行过滤(我进一步猜测 ActionID 是一个自动编号,并且您有一行 {ActionID = 1, actiontype = 'repair'} 只是偶然...但这可能推断得太远了:)

我很惊讶@David Steele的答案在Access(ACE,Jet,等等)中有效,因为他从JOIN 子句(但是,如果确实如此——建议使用链接表——那么您应该“接受”该答案)。但我也可以抵制“整理它们”,以便 ON 子句靠近表名称:

SELECT BuildingDetails.*, Contractors.Item, ActionDetails.ActionType
  FROM ((DormData 
         INNER JOIN Contractors 
            ON Contractors.ID = DormData.ItemID)
         INNER JOIN BuildingDetails 
            ON BuildingDetails.BuildingID = DormData.BuildingID)
         INNER JOIN ActionDetails
            ON ActionDetails.ActionID = DormData.ActionID
 WHERE ActionDetails.ActionType = 'repair';

I suspect you only need to filter using actiontype = 'repair' (I further guess that ActionID 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 the ON clauses are close to the table names:

SELECT BuildingDetails.*, Contractors.Item, ActionDetails.ActionType
  FROM ((DormData 
         INNER JOIN Contractors 
            ON Contractors.ID = DormData.ItemID)
         INNER JOIN BuildingDetails 
            ON BuildingDetails.BuildingID = DormData.BuildingID)
         INNER JOIN ActionDetails
            ON ActionDetails.ActionID = DormData.ActionID
 WHERE ActionDetails.ActionType = 'repair';
殤城〤 2024-11-13 00:03:54

将其添加到 select 语句的末尾以解决问题:

where actiondetails.actiontype = 'repair' or actiondetails.actionid = 1

Add this to the end of your select statement to fix the issue:

where actiondetails.actiontype = 'repair' or actiondetails.actionid = 1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文