我想获得10个最接近的经度和纬度位置。我将经度和纬度存储为双精度。我试过了:
SELECT * FROM company as dest where 3956 * 2 * ASIN(SQRT( POWER(SIN((122.4058 - abs( dest.latitude)) * pi()/180 / 2),2) + COS(122.4058 * pi()/180 ) * COS( abs (dest.latitude) * pi()/180) * POWER(SIN((37.7907 – dest.longitude) * pi()/180 / 2), 2) )) as dis <10 and ORDER BY dis limit 10;
但是我得到这个错误:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '– dest.longitude) * pi()/180 / 2), 2) )) as dis <10 and ORDER BY dis limit 10 ' at line 1
如何解决这个错误?
try this:
POWER(SIN((37.7907 – abs(dest.longitude))
EDIT2:
SELECT *,3956 * 2 * ASIN(SQRT( POWER(SIN((122.4058 - abs(dest.latitude)) * pi()/180 / 2),2) + COS(122.4058 * pi()/180 ) * COS( abs(dest.latitude) * pi()/180) * POWER(SIN((37.7907 - abs(dest.longitude)) * pi()/180 / 2), 2) )) as dis FROM company as dest HAVING dis <10 ORDER BY dis limit 10;
我复制了您的sql代码并将其放入具有语法高亮显示支持的编辑器(Sublime2)和字符,错误指向(看起来像减号)实际上是另一个符号..
根据这个网页,这个字符被称为EN DASH(你可以在链接末尾看到它的utf8-十六进制代码:))http://www.utf8-character.info/!% E2 % 80% 93
尝试用一个简单的减号替换这个字符。