Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/76.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 获取数据库中最近的位置_Mysql_Sql_Database - Fatal编程技术网

Mysql 获取数据库中最近的位置

Mysql 获取数据库中最近的位置,mysql,sql,database,Mysql,Sql,Database,我试图从数据库中获取用户输入的最近位置(最近的存储基于纬度和经度),因此根据用户的邮政编码,我将其转换为纬度和经度,并从这些结果中,我需要搜索我的数据库,以查找最接近这些值的存储。我保存了所有商店的经度和纬度,到目前为止(不看前面的问题),我尝试了以下方法: SELECT * FROM mystore_table WHERE `latitude` >=(51.5263472 * .9) AND `longitude` <=(-0.3830181 * 1.1) ORDER BY

我试图从数据库中获取用户输入的最近位置(最近的存储基于纬度和经度),因此根据用户的邮政编码,我将其转换为纬度和经度,并从这些结果中,我需要搜索我的数据库,以查找最接近这些值的存储。我保存了所有商店的经度和纬度,到目前为止(不看前面的问题),我尝试了以下方法:

SELECT * 
FROM mystore_table 
WHERE `latitude` >=(51.5263472 * .9) AND `longitude` <=(-0.3830181 * 1.1) 
ORDER BY abs(latitude - 51.5263472 AND longitude - -0.3830181) limit 1;
选择*
从mystore_表

其中,`latitude`>=(51.5263472*.9)和`longitude`按
顺序进行逻辑运算,而不是算术运算。试试这个:

SELECT * 
FROM mystore_table 
WHERE `latitude` >=(51.5263472 * .9) AND `longitude` <=(-0.3830181 * 1.1) 
ORDER BY abs(latitude - 51.5263472) + abs(longitude - -0.3830181)
limit 1;
选择*
从mystore_表
其中`纬度'>=(51.5263472*.9)和`经度`