SQL服务器:查询两个表的相关性
SQL Server : query correlation from two tables
我有两个 table 正在尝试关联以下数据:
Tasklist
:
Hostname PID Process Module
-----------------------------------------------
Host1 1 sample.exe sample.dll
Host2 4 sample2.exe sample2.dll
Host5 11 sample5.exe sample.dll
和
Netstat
:
Hostname PID Address .... (many other columns I don't care about)
------------------------------
Host9 8 10.10.10.10
Host2 67 78.66.44.22
Host8 78 54.22.11.33
Host1 1 77.33.22.11
我想要做的是 return 任务列表 table 中的所有内容,其中任务列表 table 中的主机名和 PID 也在 Netstat [=30] 中找到=].因此在这种情况下,它将 return 任务列表的第一行 table 因为 Host1 和 PID 1 存在于 Netstat 中。
我是 SQL 的新手,真的不知道该怎么做,如有任何帮助,我们将不胜感激!
您应该在两个表上使用联接以从两个表中获取匹配值,但因为您需要 tasklist
中的值。你可以这样做,
Select tasklist.*,netstat.address
From tasklist join netstat
On tasklist.pid = netstat.pic and tasklist.hostname = netstat.hostname
我有两个 table 正在尝试关联以下数据:
Tasklist
:
Hostname PID Process Module
-----------------------------------------------
Host1 1 sample.exe sample.dll
Host2 4 sample2.exe sample2.dll
Host5 11 sample5.exe sample.dll
和
Netstat
:
Hostname PID Address .... (many other columns I don't care about)
------------------------------
Host9 8 10.10.10.10
Host2 67 78.66.44.22
Host8 78 54.22.11.33
Host1 1 77.33.22.11
我想要做的是 return 任务列表 table 中的所有内容,其中任务列表 table 中的主机名和 PID 也在 Netstat [=30] 中找到=].因此在这种情况下,它将 return 任务列表的第一行 table 因为 Host1 和 PID 1 存在于 Netstat 中。
我是 SQL 的新手,真的不知道该怎么做,如有任何帮助,我们将不胜感激!
您应该在两个表上使用联接以从两个表中获取匹配值,但因为您需要 tasklist
中的值。你可以这样做,
Select tasklist.*,netstat.address
From tasklist join netstat
On tasklist.pid = netstat.pic and tasklist.hostname = netstat.hostname