简体   繁体   English

如何从第三个查询中排除值(访问)

[英]How can I exclude values from a third query (Access)

I have a query that shows me a listing of ALL opportunities in one query 我有一个查询,向我显示一个查询中所有机会的列表

I have a query that shows me a listing of EXCLUSION opportunities, ones we want to eliminate from the results 我有一个查询,向我显示了排除机会列表,我们希望从结果中消除这些机会

I need to produce a query that will take everything from the first query minus the second query... 我需要产生一个查询,该查询将从第一个查询减去第二个查询的所有内容...

SELECT DISTINCT qryMissedOpportunity_ALL_Clients.*
FROM qryMissedOpportunity_ALL_Clients INNER JOIN qryMissedOpportunity_Exclusions ON
([qryMissedOpportunity_ALL_Clients].[ClientID] <> [qryMissedOpportunity_Exclusions].[ClientID])
AND
([qryMissedOpportunity_Exclusions].[ClientID] <> [qryMissedOpportunity_Exclusions].[BillingCode])

The initial query works as intended and exclusions successfully lists all the hits, but I get the full listing when I query with the above which is obviously wrong. 初始查询按预期方式工作,并且排除项成功列出了所有匹配,但是当我使用上述查询进行查询时,我得到了完整列表,这显然是错误的。 Any tips would be appreciated. 任何提示将不胜感激。

EDIT - Two originating queries 编辑-两个原始查询

qryMissedOpportunity_ALL_Clients (1) qryMissedOpportunity_ALL_Clients(1)

SELECT MissedOpportunities.MOID, PriceList.BillingCode, Client.ClientID, Client.ClientName, PriceList.WorkDescription, PriceList.UnitOfWork, MissedOpportunities.Qty, PriceList.CostPerUnit AS Our_PriceList_Cost, ([MissedOpportunities].[Qty]*[PriceList].[CostPerUnit]) AS At_Cost, MissedOpportunities.fBegin
FROM PriceList INNER JOIN (Client INNER JOIN MissedOpportunities ON Client.ClientID = MissedOpportunities.ClientID) ON PriceList.BillingCode = MissedOpportunities.BillingCode
WHERE (((MissedOpportunities.fBegin)=#10/1/2009#));

qryMissedOpportunity_Exclusions qryMissedOpportunity_Exclusions

SELECT qryMissedOpportunity_ALL_Clients.*, MissedOpportunity_Exclusions.Exclusion, MissedOpportunity_Exclusions.Comments
FROM qryMissedOpportunity_ALL_Clients INNER JOIN MissedOpportunity_Exclusions ON (qryMissedOpportunity_ALL_Clients.BillingCode = MissedOpportunity_Exclusions.BillingCode) AND (qryMissedOpportunity_ALL_Clients.ClientID = MissedOpportunity_Exclusions.ClientID)
WHERE (((MissedOpportunity_Exclusions.Exclusion)=True));

One group needs to see everything, the other needs to see things they havn't deamed as "valid" missed opportunity as in, we've seen it, verified why its there and don't need to bother critiquing it every single month. 一组需要看到所有事物,另一组需要看到他们没有被视为“有效”错过的机会的事情,例如,我们已经看到了它,验证了为什么它在那里并且不需要费心每个月对其进行批评。

Looking at your query rewritten to use table aliases so I can read it... 查看您的查询以使用表别名进行重写,以便我可以阅读...

SELECT DISTINCT c.*
FROM qryMissedOpportunity_ALL_Clients c
   JOIN qryMissedOpportunity_Exclusions e
      ON c.ClientID <> e.ClientID
        AND  e.ClientID <> e.BillingCode

This query will produce a cartesian product of sorts... each and every row in qryMissedOpportunity_ALL_Clients will match and join with every row in qryMissedOpportunity_Exclusions where ClientIDs do not match... Is this what you want?? 此查询将产生各种笛卡尔乘积... qryMissedOpportunity_ALL_Clients每一行都将匹配并与qryMissedOpportunity_Exclusions中的每一行都连接,其中ClientID 匹配...这是您想要的吗? Generally join conditions are based on a column in one table being equal to the value of a column in the other table... Joining where they are not equal is unusual ... 通常,连接条件基于一个表中的列等于另一表中的列的值。在不相等的情况下进行连接是不寻常的...

Second, the second iniquality in the join conditions is between columns in the same table (qryMissedOpportunity_Exclusions table) Are you sure this is what you want? 第二,联接条件中的第二个不等式是同一表(qryMissedOpportunity_Exclusions表)中的列之间。确定要这样做吗? If it is, it is not a join condition, it is a Where clause condition... 如果是,那么它不是联接条件,而是Where子句条件...

Second, your question mentions two queries, but there is only the one query (above) in yr question. 其次,您的问题提到了两个查询,但是您的问题中只有一个查询(上面)。 Where is the second one? 第二个在哪里?

Generally you can exclude a table by doing a left join and comparing against null: 通常,您可以通过左连接并与null比较来排除表:

SELECT t1.* FROM t1 LEFT JOIN t2 on t1.id = t2.id where t2.id is null;

Should be pretty easy to adopt this to your situation. 在您的情况下采用此方法应该很容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM