SQL 查询 - 节点关闭

SQL Query - Nodes down

我有以下 3 个 table,我想 运行 一个 SQL 查询来查找哪些节点的所有接口都关闭了......这是来自 table 下面是节点 x2,因为(该节点存在于 'outage' table 中,并且 'outage' 和 'interface' [=29] 中的接口数均为 2 =]).

node
id name
1  x1
2  x2
3  x3

outage
id nodeid ip       duration
1  1      1.1.1.1  1h
2  2      2.2.2.1  2h
2  2      2.2.2.2  2h
3  3      3.3.3.1  5h

interface
id nodeid ip
1  1      1.1.1.1
1  1      1.1.1.2
1  1      1.1.1.3
2  2      2.2.2.1
2  2      2.2.2.2
3  3      3.3.3.1
3  3      3.3.3.2
3  3      3.3.3.3
3  3      3.3.3.4

我尝试编写许多 sql 查询但都失败了。我心中的伪代码如下:

如果 'the node is present in the outage table' 和 if '中断中的接口数 table = 接口中的接口数 table 然后该节点被视为已关闭。 否则该节点要么已启动,要么其一个或多个接口已关闭。

关于如何解决这个问题的任何想法或想法!

P.S。使用 PostgreSQL

最简单的方法是检查节点是否没有未关闭的接口。

SELECT *
FROM node AS n
WHERE 
  NOT EXISTS(
    SELECT *
    FROM interface AS i
    LEFT JOIN outage AS o
      ON (i.nodeid,i.ip) = (o.nodeid,o.ip)
    WHERE i.nodeid = n.id AND o.id IS NULL
  )