我的计数功能有问题... 我想隔离G10多边形旁边的所有多边形,我想计算我的多边形(邻域)中的点数(地铁站),但即使答案必须为0,我也希望得到答案。
我使用了以下声明:
select a2.name, count(m.geom)
from arr a1, arr a2, metro m
where n1.code='G10'
and ((st_touches(a1.geom, a2.geom)) or
(st_overlaps(a1.geom, a2.geom)))
and ST_Contains(a2.geom, s.geom)
group by a2.name, m.geom
我知道问题在于where子句的and ST_Contains(a2.geom, s.geom)
部分,但我现在不知道如何解决它!
答案 0 :(得分:1)
使用明确的LEFT JOIN
:
SELECT a1.name, COUNT(a2.code)
FROM arr a1
LEFT JOIN
arr a2
ON ST_Intersects(a1.geom, a2.geom)
WHERE a1.code = 'G10'
我不包括其他表,因为您在原始查询中有明显的拼写错误,并且不清楚它们应该如何连接