我使用postgres 11并尝试从表cmdb_mgmt中获取所有列,将两个表与列hostname (fkey)进行匹配,在表config_data.interface列中,last_seen是null。这是我拥有的查询,它运行但不返回结果:
select
*
from
cmdb_mgmt, config_data.interface
where
config_data.interface.last_seen in (
select config_data.interface.last_seen from config_data.interface where config_data.interface.last_seen is null
);一个潜在的警告是,由于hostname是复合pkey的一部分,config_data.interface中存在许多相同的值。然而,它们在cmdb_mgmt中只存在一次。
发布于 2021-08-04 01:03:09
好吧,你可能会想这样做,而不是:
SELECT cmdb_mgmt.*
FROM cmdb_mgmt
WHERE cmdb_mgmt.hostname IN (
SELECT config_data.interface.hostname
FROM config_data.interface
WHERE config_data.interface.last_seen IS NULL
);你的版本有一个偶然交叉连接/笛卡尔产品。
发布于 2021-08-04 00:56:51
通过使用此查询,我能够获得所需的结果。我有一些简单的语法问题。
select
cmdb_mgmt.*
from
cmdb_mgmt, config_data.interface
where
cmdb_mgmt.hostname in (
select config_data.interface.hostname from config_data.interface where config_data.interface.last_seen is null
);https://stackoverflow.com/questions/68644172
复制相似问题