1

次の内容(ホスト)を持つ(postgres)SQLテーブルがあります。

   ip_address   |  mac_address   | hostname | device | physical_port
----------------+----------------+----------+--------+---------------
111.111.111.111 | aaaa.aaaa.aaaa | hosta    | swh-a  | Gi1/1
111.111.111.112 | bbbb.bbbb.bbbb | hostb    | swh-b  | Gi2/1
111.111.111.113 | cccc.cccc.cccc | hostc    | swh-c  | Gi3/1

テーブル間のポイントツーポイント リンクを含む別のテーブル (ピア) がありdevicesます。

 device | physical_port | peer_device | peer_physical_port 
 -------+---------------+-------------+----------------------+
 swh-a  | Gi1/20        | swh-b       | Gi2/1
 swh-b  | Gi2/1         | swh-a       | Gi1/20
 swh-b  | Gi2/1         | swh-c       | Gi3/1
 swh-c  | Gi3/1         | swh-b       | Gi2/1

基本的に、Peers テーブルに含まれる Hosts テーブルからエントリを除外して、次のようにします。

   ip_address   |  mac_address   | hostname | device | physical_port
----------------+----------------+----------+--------+---------------
111.111.111.111 | aaaa.aaaa.aaaa | hosta    | swh-a  | Gi1/1

(その場合、 Peers テーブル内に存在します) device=swh-b physical_port=Gi2/1device=swh-c physical_port=Gi3/1

4

4 に答える 4

0

これを試して..

SELECT  * 
FROM    Host
WHERE   device NOT IN (SELECT device FROM Peers )
AND     physical_port NOT IN (SELECT physical_port FROM Peers)
于 2013-11-13T04:43:29.173 に答える
0

You need something like this:

SELECT *
FROM Host h
LEFT JOIN Peers p ON p.device= h.device and p.physical_port = h.physical_port
WHERE p.ID IS NULL
于 2013-11-13T02:16:04.007 に答える