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是经纬度,想问问怎么个思路写的,这是别人写的给我研究研究。


泛舟湖上清波郎朗
浏览 351回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java