我有两个查询,一个返回前10个最近的位置:
DECLARE @center GEOGRAPHY
SET @center = geography::Point(@Latitude, @Longitude, 4326)
SELECT TOP 10
[Physical_Address_Street]
, [Physical_Address_Local]
, [Physical_Address_State]
, [Physical_Address_Zip]
, [Phone_Number]
FROM Gas_Stations
WHERE Location_Type = 1
ORDER BY @center.STDistance(Location) ASC
然后是另一个将获得与传入的纬度和长度的距离
SELECT Location.STDistance(geography::Point(51, -2, 4326)) * 0.00062137119
FROM [MY_DB].[dbo].[Gas_Station]
这两个都查询同一个表,那么如何组合这些并获得十个点中每个点的距离?
答案 0 :(得分:1)
SELECT TOP 10
*,
geography::Point(51, -2, 4326).STDistance(location) * 0.00062137119
FROM gas_stations
WHERE location_type = 1
ORDER BY
@center.STDistance(location) ASC