Access - 使用一个查询计算多个表中的相同值

Access - Count same value in multiple tables with one query

我收到了几个不同的安全报告,我正在尝试处理这些报告。我想计算一个特定 IP 地址在 2 个不同的 table 中出现的次数。

我希望它看起来像这样:

IP 地址表 1 表 2

xxx.xxx.xxx 12 13

我看到很多人要求计算不同 table 中的不同值,但不同 table 中的值不同,所以我有点困惑。

我通过使用连接和计数功能使用内置查询设计器创建了我的初始计数 table;但是,如果我尝试多个连接,数字会变得非常奇怪,我不知道发生了什么。当我尝试使用一个 table:

时,访问吐出这个 SQL
SELECT [Dell Printers by IP].Address, Count([Apache 12-24].[Vulnerability Title]) AS [CountOfVulnerability Title]
FROM [Apache 12-24] INNER JOIN [Dell Printers by IP] ON [Apache 12-24].[Asset IP Address] = [Dell Printers by IP].Address
GROUP BY [Dell Printers by IP].Address;

此外,扩展到 table 多于 2 个有多容易?

不知道你的 table 在数据库中是如何关联的,我建议使用相关子查询:

select 
  [ip addresses].[ip address],
  (select count(*) from table1 where table1.[ip address] = [ip addresses].[ip address]) as t1,
  (select count(*) from table2 where table2.[ip address] = [ip addresses].[ip address]) as t2
from
  [ip addresses]

假设您要查询的 IP 地址位于一个名为 ip addresses.

的 table 中