SQLite,Python3

问题描述 投票:0回答:1

我对SQLite有问题。我有一个包含5个表的数据库。

表1:扫描列:scan_id和scandate

表2:系统列:system_id,ip,dns ..

表3:端口列:port_id,协议,端口,服务

表4:插件列:plugin_id,PluginName,描述

表5:地图列:map_id,scan_id,system_id,port_id,plugin_id

因此,一个系统可以具有多个端口,而一个端口可以具有一对多注册的插件。现在,我想了解以下内容:最后扫描日

`system_IP, protocol, port, service and all plugins identified on that systems port` 

此刻,我被此命令卡住:

`SELECT system_IP, protocol, port, service, PluginName FROM maps
 INNER JOIN scans ON (maps.scan_id = scans.scan_id)
 INNER JOIN systems ON (maps.system_id = systems.system_id)
 INNER JOIN ports ON (maps.ports_id = ports.ports_id)
 INNER JOIN plugins ON (maps.plugin_id = plugins.plugin_id)
 WHERE scan_id=1`

结果是:

`123.456.789.1, TCP, 22, SSH, Plugin1
 123.456.789.1, TCP, 80, HTTP, Plugin2
 123.456.789.1, TCP, 80, HTTP, Plugin3`

我想要的是以下内容:

`123.456.789.1, TCP, 22, SSH, Plugin1
 123.456.789.1, TCP, 80, HTTP, Plugin2, Plugin3, Plugin4
 123.456.789.1, TCP, 443, SSH, Plugin3`

我该怎么做?

sql sqlite
1个回答
0
投票

现在,我想获取以下信息:在最后扫描日

这表明类似:

SELECT system_IP, protocol, p.port, service, pl.PluginName
FROM (SELECT s.*
      FROM scans s
      ORDER BY scandate DESC
      LIMIT 1
     ) s JOIN
     maps m
     ON m.scan_id = s.scan_id JOIN
     systems sy
     ON m.system_id = sy.system_id JOIN
     ports p
     ON m.ports_id = p.ports_id JOIN
     plugins pl
     ON m.plugin_id = pl.plugin_id;
© www.soinside.com 2019 - 2024. All rights reserved.