我收到了几份不同的安全报告,我正在尝试处理这些报告。我想计算一下一个特定的IP地址在两个不同的表中出现了多少次。
我希望它看起来像这样:
IP Address Table1 Table2
xxx.xxx.xxx 12 13
我见过很多人要求在不同的表中计算不同的值,但在不同的表中不是相同的值,所以我有点困惑。
我使用内置的查询设计器通过连接和计数功能创建了一个表的初始计数;但是,如果我尝试多个连接,这个数字会变得非常奇怪,并且我不知道发生了什么。当我尝试使用一个表时,Access会吐出以下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;此外,扩展到比只有2个表更多的表有多容易?
发布于 2019-01-09 04:04:36
在不知道表在数据库中是如何相关的情况下,我建议使用相关子查询:
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的表中。
https://stackoverflow.com/questions/54098505
复制相似问题