sql计算离哪里的距离问题。

手机端传个经纬度 想要查询到指定商家的距离

sql:String sql = "SELECT c.pubid,c.couponname couponName,c.type,c.couponfee / 100 couponfee,c.pic1_path picPath,count(c.fetch_num) AS num,g.category_name categoryName,"; 
        sql += " IF(ISNULL(r.minfee) || LENGTH(trim(r.minfee))<1,r.maxfee,r.minfee) fee,sc.id shopCartId,";
        sql += " ifnull((SELECT min(round(6378.138 * 2 * asin(sqrt(pow(sin(("+positionNS+" * pi() / 180 - s.positionNS * pi() / 180) / 2),2) + cos("+positionNS+" * pi() / 180) * cos(s.positionNS * pi() / 180) ";
        sql += " * pow(sin(("+positionWE+"* pi() / 180 - s.positionWE * pi() / 180) / 2),2))),2)) AS distance";
        sql += " FROM market s,saas m WHERE s.saas = m.id AND s.saas = ru.saas ) ,0) distance";
        sql += " FROM couponpublish c,hh_coupons_category g,ruledescribe r,actionrule ru, shop_cart sc";
        sql += " where c.category_id = g.id and c.getruleid=r.ruleid    and r.actionfile=ru.actionfile    and sc.pub_id = c.pubid    and sc.user_id = '"+userId+"'";
        sql += " GROUP BY c.pubid ORDER BY sc.create_time DESC";
        
         List<Map> list=super.findListbySqlReturnMap(sql);

s.positionWE positionNS是经纬度,想问问怎么个思路写的,这是别人写的给我研究研究。

阅读 2.8k
1 个回答
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题