作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想知道是否有办法从空间数据列中查询最近的 N 个邻居,丢弃重复项。
例如,我的查询如下所示:
SELECT TOP (@N) Point.STDistance(@Point) AS Distance
FROM MyTable
WHERE Point.STDistance(@Point) IS NOT NULL --For Spatial Index usage
ORDER BY Distance;
Distance
3906,81969203873
3906,81969203873
5321,62614141754
5756,28719382942
最佳答案
根据 Nearest Neighbor Query and Spatial Indexes 上的 MSDN 描述,您需要使用 STDistance()
在 ORDER BY
条款。
The first expression in the ORDER BY clause must use the STDistance() method.
Sort order for the first STDistance() expression in the ORDER BY clause must be ASC.
GROUP BY
或
CTE
或
subquery
以避免任何潜在的重复。
关于sql-server - SQL Server 查询最近邻 DISTINCT TOP N ORDER BY 距离的空间数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42694366/
我是一名优秀的程序员,十分优秀!