Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 基于距离返回匹配的sql行_Mysql_Sql_Database_Gis - Fatal编程技术网

Mysql 基于距离返回匹配的sql行

Mysql 基于距离返回匹配的sql行,mysql,sql,database,gis,Mysql,Sql,Database,Gis,其实很简单,我只是不知道怎么做 我有一张桌子: table locations location_id coordinates name ------------------------------------- 当我从设备接收到纬度和经度时,我将其存储在mysql中POINT(Long,Lat)类型的变量中 我试图获取位置表中距离小于或等于8米的所有行 我的质询如下: SELECT * FROM locations where st_distance_sphere(@user

其实很简单,我只是不知道怎么做

我有一张桌子:

table locations 
location_id     coordinates    name
-------------------------------------
当我从设备接收到纬度和经度时,我将其存储在mysql中POINT(Long,Lat)类型的变量中

我试图获取位置表中距离小于或等于8米的所有行

我的质询如下:

SELECT * FROM locations where st_distance_sphere(@userCoords, @pt1)  <= 8; 

从st_distance_sphere(@userCoords,@pt1)所在的位置选择*只需放置列而不是
@pt1
(假设列类型为点):

选择*
从地点

其中,st_distance_sphere(@userCoords,coordinates)只需放置列,而不是
@pt1
(假设列类型为点):

选择*
从地点

这里是距离球(@userCoords,坐标)救世主。谢谢你帮助一个新手:DSavior。谢谢你帮了一个新手
SELECT * 
FROM locations 
where st_distance_sphere(@userCoords, coordinates)  <= 8;