如果我正确理解了您的问题,您希望使用显示 qry_ip_blacklist 表中 ip_address 数量的新列执行第一个查询。
如果是这样并且 tbl_ip_addresses 没有更多列,则此查询将执行此操作:
SELECT tbl_ip_addresses.ip_address, tbl_ip_addresses.selected, COUNT(qry_ip_blacklist.ip_address )
FROM tbl_ip_addresses
LEFT JOIN qry_ip_blacklist
ON qry_ip_blacklist .ip_address = tbl_ip_addresses.ip_address
WHERE (tbl_ip_addresses.selected=True)
GROUP BY tbl_ip_addresses.ip_address, tbl_ip_addresses.selected
如果此查询仍然不起作用,您可以使用黑名单 ip 地址查询地址,对于没有的人可以查询另一个地址:
SELECT tbl_ip_addresses.ip_address, tbl_ip_addresses.selected, COUNT(qry_ip_blacklist.ip_address)
FROM tbl_ip_addresses
INNER JOIN qry_ip_blacklist ON qry_ip_blacklist .ip_address = tbl_ip_addresses.ip_address
WHERE (tbl_ip_addresses.selected=True)
GROUP BY tbl_ip_addresses.ip_address, tbl_ip_addresses.selected
UNION
SELECT tbl_ip_addresses.ip_address, tbl_ip_addresses.selected, 0
FROM tbl_ip_addresses
WHERE (tbl_ip_addresses.selected=True) AND tbl_ip_addresses.ip_address NOT INT (SELECT ip_addresses FROM qry_ip_blacklist)