【发布时间】:2015-06-15 03:38:13
【问题描述】:
我有两个数据集:1. ZipCodes 和 2. Neighborhoods(将它们视为县)。
我想加入邮政编码覆盖的每个社区。大多数社区只会在一个邮政编码之内,但在某些情况下,社区会跨越两个。比如:
邻域 1 位于 20001 内部
邻里 2 在 20002 里面
邻里3在20001,20002里面
这是我目前所拥有的:
SELECT name, zipcode
FROM
neighborhood_names nn, dc_zipcode_boundries dzb
WHERE ST_Intersects(nn.the_geom, dzb.the_geom);
注意:根据 cmets 更新到 within,现在可以得到每个邻域的答案,但仍然无法让 Array 函数按预期响应。
【问题讨论】:
-
您并没有错过任何这样的东西,尽管您可能想要使用 ST_Intersects,它还将获取跨越边界的那些邮政编码。如果您想为每个邻域提供一行输出,则可以使用 array_agg 函数以及按名称进行的 GROUP,它将为您的第三个示例行返回类似 3, [20001, 20002] 的内容,而不是两行。跨度>
-
所以我尝试了这个:
select nn.the_geom_webmercator, name, string_Agg(zipcode, ',') as zipcodeArr from
neighbor_names nn, dc_zipcode_boundries dzb where ST_Intersects(nn.the_geom,dzb .the_geom)
并且通常会出错:列“nn.the_geom_webmercator”必须出现在 GROUP BY 子句中或用于聚合函数中我做错了什么?