Return 根据距离匹配 sql 行
Return matching sql rows based on distance
其实很简单,我只是不知道该怎么做。
我有一个 table:
table locations
location_id coordinates name
-------------------------------------
当我从设备接收到纬度和经度时,我将其存储在 mysql 类型为 POINT(Long, Lat) 的变量中。
我正在尝试获取位置 table 中距离小于或等于八米的所有行。
我的查询如下:
SELECT * FROM locations where st_distance_sphere(@userCoords, @pt1) <= 8;
我知道这个查询是错误的,因为 @pt1
与列坐标没有关联。如何隔离坐标列中的特定值和 return 匹配的行列表?
st_distance_sphere()
函数只是计算两个坐标之间的距离,return 是一个数字。
提前致谢!
所有你需要的是把列而不是@pt1
(假设列类型是点):
SELECT *
FROM locations
where st_distance_sphere(@userCoords, coordinates) <= 8;
这将为您提供来自@userCoords
的坐标为 8 或更小的所有行
其实很简单,我只是不知道该怎么做。
我有一个 table:
table locations
location_id coordinates name
-------------------------------------
当我从设备接收到纬度和经度时,我将其存储在 mysql 类型为 POINT(Long, Lat) 的变量中。
我正在尝试获取位置 table 中距离小于或等于八米的所有行。
我的查询如下:
SELECT * FROM locations where st_distance_sphere(@userCoords, @pt1) <= 8;
我知道这个查询是错误的,因为 @pt1
与列坐标没有关联。如何隔离坐标列中的特定值和 return 匹配的行列表?
st_distance_sphere()
函数只是计算两个坐标之间的距离,return 是一个数字。
提前致谢!
所有你需要的是把列而不是@pt1
(假设列类型是点):
SELECT *
FROM locations
where st_distance_sphere(@userCoords, coordinates) <= 8;
这将为您提供来自@userCoords
的坐标为 8 或更小的所有行