【问题标题】:MS Access query WHERE NOT EXISTSMS Access 查询 WHERE NOT EXISTS
【发布时间】:2016-04-27 15:39:54
【问题描述】:

我一直在四处寻找,但无法解决这个问题。

我有两个来自两个查询的表

SELECT [Account Combination].[Account Number] & [Account Combination].[Cost Center] & [Account Combination].Amount as Val1 FROM [Account Combination];

SELECT [Account Combination].[Account Number] & [Account Combination].[Cost Center] & [Account Combination].Amount AS Val1 FROM [Account Information] INNER JOIN ([Cost Center] INNER JOIN [Account Combination] ON [Cost Center].[Cost Center Number] = [Account Combination].[Cost Center]) ON [Account Information].[Account Number] = [Account Combination].[Account Number];

Table1 有 1800 行,Table2 有 1600 行。我想看看在 Table1 中找到哪些在 Table2 中没有找到,即 200。

我已经尝试过 Table1 NOT EXISTS Tabel2,但由于一直出现语法错误,因此无法使其正常工作。

感谢您的宝贵时间, 西蒙。

【问题讨论】:

  • 正确标记您的问题以快速获得正确答案

标签: sql ms-access


【解决方案1】:

您可以使用LEFT OUTER JOINWHERE 条件(如下所示)来完成此操作

select t1.*
from (SELECT [Account Combination].[Account Number] & [Account Combination].[Cost Center] & [Account Combination].Amount as Val1 
FROM [Account Combination]) t1
left join (
SELECT [Account Combination].[Account Number] & [Account Combination].[Cost Center] & [Account Combination].Amount AS Val1 
FROM [Account Information] INNER JOIN ([Cost Center] INNER JOIN [Account Combination] 
ON [Cost Center].[Cost Center Number] = [Account Combination].[Cost Center]) 
ON [Account Information].[Account Number] = [Account Combination].[Account Number]) t2 
on t1.Val1 = t2.Val1 
where t2.Val1 is null;

【讨论】:

    【解决方案2】:

    看看:This excellent answer

    它回答了如何使用 NOT EXISTS 的问题。 顺便说一下,IS NULL 子句更快。

    【讨论】:

      猜你喜欢
      • 2019-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多