Mysql 我在一个查询中发现了一个错误语法

Mysql 我在一个查询中发现了一个错误语法,mysql,mysql-error-1064,Mysql,Mysql Error 1064,我在MySQL查询中有一个错误,但我不知道它是什么 错误是 错误1064 42000:您的SQL语法有错误;检查 与右边的MySQL服务器版本相对应的手册 使用近“sin radians30.9006547*sin radianslat”的语法 震级,8表示与3号线的距离 疑问是 SELECT h.* , ROUND(1.609344 * 3956 * acos( cos( radians(30.9006547) ) * cos( radians(latitude) ) * cos(

我在MySQL查询中有一个错误,但我不知道它是什么

错误是

错误1064 42000:您的SQL语法有错误;检查 与右边的MySQL服务器版本相对应的手册 使用近“sin radians30.9006547*sin radianslat”的语法 震级,8表示与3号线的距离

疑问是

SELECT h.*
     , ROUND(1.609344 * 3956 * acos( cos( radians(30.9006547) ) * cos( radians(latitude) ) * 
cos( radians(longitude) - radians(30.8524007) ) sin( radians(30.9006547) ) * sin( radians(latitude) ) ) ,8) as distance 
  FROM helper h
 where is_available = 1 
   and is_active = 1 
   and is_approved = 1 
   and ROUND((1.609344 * 3956 * acos( cos( radians(30.9006547) ) * cos( radians(latitude) ) * 
cos( radians(longitude) - radians(30.8524007) )sin( radians(30.9006547) ) * sin( radians(latitude) ) ) ) ,8) <= 60
 order 
   by distance LIMIT 3;

在代码中,在cos和sin之间缺少+符号

  SELECT h.*
       , ROUND(1.609344 * 3956 * acos( cos( radians(30.9006547) ) * cos( radians(latitude) ) * 
  cos( radians(longitude) - radians(30.8524007) ) +  /*<<<<<< here */
  sin( radians(30.9006547) ) * sin( radians(latitude) ) ) ,8) as distance 
    FROM helper h
   where is_available = 1 
     and is_active = 1 
     and is_approved = 1 
     and ROUND((1.609344 * 3956 * acos( cos( radians(30.9006547) ) * cos( radians(latitude) ) * 
  cos( radians(longitude) - radians(30.8524007) ) + /* <<<< and here */
   sin( radians(30.9006547) ) * sin( radians(latitude) ) ) ) ,8) <= 60
   order 
     by distance LIMIT 3;

这是一个计算地球上距离的函数示例,单位为km。如果你喜欢它,就用它。。。不要忘记在构造函数之前和之后更改分隔符

CREATE DEFINER=`root`@`localhost` FUNCTION `geo_distance_km`(lat1 double, lon1 double, lat2 double, lon2 double) RETURNS double
begin
   declare R int DEFAULT 6372.8;
   declare phi1 double;
   declare phi2 double;
   declare d_phi double;
   declare d_lambda double;
   declare a double;
   declare c double;
   declare d double;
   set phi1 = radians(lat1);
   set phi2 = radians(lat2);
   set d_phi = radians(lat2-lat1);
   set d_lambda = radians(lon2-lon1);
   set a = sin(d_phi/2) * sin(d_phi/2) +
         cos(phi1) * cos(phi2) *
         sin(d_lambda/2) * sin(d_lambda/2);
   set c = 2 * atan2(sqrt(a), sqrt(1-a));
   set d = R * c;
   return d;
   end 

你引用的查询中没有31…我知道我只是把它去掉了,你的意思是纬度和经度,我的数据库中有一个geo_distance_km函数。它节省了大量的打字。就这么说吧。另外,很明显,Sina的左边有东西不见了。如果可能的话,你能告诉我吗?如何使用它?查询1064中仍然存在错误:“radians31.50546547*sin radianslatitude,8答案更新……”附近的语法错误。。。。。。。where条件中缺少相同的+符号。。因此,在适当的位置添加+,如果你看起来更好,你会看到错误消息不一样,第二个显示相同错误代码的不同部分哦,真的谢谢你,我真的很抱歉,我对MySQL很不了解,我只是在学习,我不知道把它放在哪里,就像我正在使用的node.js函数一样,我认为我缺乏MySQL的基础知识和功能如果我要使用它,我能得到用户的激活和批准吗?就像我在上面发布的查询一样,是的,您只需调用函数来代替所有的回合…acos…lat。。东西,谢谢!我会弄明白的