我正在尝试在sql 2008中执行空间查询 - >对于给定的POI列表(兴趣点,长/纬度GEOGRAPHY
数据),它们存在于(多字段GEOGRAPHY
数据中)的邮政编码中。
所以这是我试过的查询,但它在语法上是不正确的: -
SELECT PostCodeId, ShapeFile
FROM Postcodes a
WHERE a.ShapeFile.STIntersects(
SELECT PointOfInterest
FROM PointOfInterests
WHERE PointOfInterestId IN (SELECT Item from dbo.fnSplit(@PoiIdList, ','))
所以这意味着我传入csv list of POI Id's and split them。这不是问题..这是STIntersects
中的子查询。那是无效的。
那么......有什么建议吗?
答案 0 :(得分:4)
怎么样:
SELECT a.PostCodeId, a.ShapeFile
FROM (SELECT Item from dbo.fnSplit(@PoiIdList, ',')) AS POI_IDs
INNER JOIN PointOfInterests
ON PointOfInterests.PointOfInterestId = POI_IDs.Item
INNER JOIN Postcodes a
ON a.ShapeFile.STIntersects(PointOfInterests.PointOfInterest) = 1