【发布时间】:2018-10-19 08:37:00
【问题描述】:
大家好,我正在尝试使用 MSSQL 中的地理数据来比较客户端与其各自服务器之间的距离。
我能够成功比较两点之间的距离。 但是仅显示最后一个条目的距离。
这是我正在使用的查询:
Declare @locations1 GEOGRAPHY;
Declare @locations2 GEOGRAPHY;
Declare @ServerID int;
SELECT @locations1 = GeoLoc from [TestDb].[dbo].[Locations] where IsClient =1;
SELECT @ServerID = ServerID from [TestDb].dbo.Locations where IsClient=1;
SELECT @locations2 = GeoLoc from [TestDb].[dbo].[Locations] where IsClient =0 AND id=@ServerID ;
select @locations1.STDistance(@locations2)/1000 As [Distance in KM]
我相信上述查询的工作原理如下:
locations1 - 具有 IsClient 为 True 的列的 GeoLocation。
ServerId - 具有 IsClient 为 True 的列的 ServerID。
locations2 - 具有 IsClient 为 0 的列的 GeoLocation 和
上面查询中获得的 ServerId 与机器的 id 匹配。
所以,
位置 1 必须具有客户端的地理位置。
location2 必须具有相应服务器的 GeoLocation。
我的餐桌设计:
当我比较时,我得到了正确的结果,但只有表中最后一个客户端和服务器条目之间的距离。 没有显示任何其他条目的距离。
如何获取所有条目的距离? 需要帮助:)。 谢谢。
【问题讨论】:
标签: sql-server tsql subquery ssms rdbms