﻿{"id":688,"date":"2011-12-12T12:46:35","date_gmt":"2011-12-12T04:46:35","guid":{"rendered":"http:\/\/nick.workao.org\/?p=688"},"modified":"2011-12-12T12:46:35","modified_gmt":"2011-12-12T04:46:35","slug":"mysql%e7%bb%8f%e7%ba%ac%e5%ba%a6%e5%9d%90%e6%a0%87%e8%b7%9d%e7%a6%bb%e8%ae%a1%e7%ae%97","status":"publish","type":"post","link":"http:\/\/nick.txtcc.com\/index.php\/other\/688","title":{"rendered":"mysql\u7ecf\u7eac\u5ea6\u5750\u6807\u8ddd\u79bb\u8ba1\u7b97"},"content":{"rendered":"<p>\u672c\u6587\u7ae0\u4e3b\u8981\u89e3\u51b3\u6570\u636e\u5e93\u5982\u679c\u5b58\u6709\u7ecf\u7eac\u5ea6\uff0c\u83b7\u53d6\u4e00\u5b9a\u8ddd\u79bb\u7684\u8bb0\u5f55\u6570<\/p>\n<p>\u9996\u5148\u6211\u4eec\u5728mysql\u5efa\u7acb\u4e00\u4e2a\u53ef\u91cd\u590d\u4f7f\u7528\u7684\u8ba1\u7b97\u4e24\u4e2a\u5750\u6807\u7ecf\u7eac\u5ea6\u7684Function<\/p>\n<pre><\/pre>\n<pre lang=\"csharp\" line=\"1\">DELIMITER $\nDROP FUNCTION IF EXISTS `GetDistance`$\n\nCREATE FUNCTION `GetDistance`(lat1 FLOAT,lng1 FLOAT, lat2 FLOAT,lng2 FLOAT)\nRETURNS  DOUBLE\nBEGIN\n    DECLARE  distance  DOUBLE;\n    if ((lat1=0 and lng1=0) or (lat2=0 and lng2=0)) then    \n        set distance=99999999.00;\n    else\n    SET distance= 2 * 6378.137* ASIN(SQRT(POW(SIN(PI() * (lat1-lat2) \/ 360), 2)+COS(PI() * lat1 \/ 180)* COS(lat2* PI() \/ 180) * POW(SIN(PI() * (lng1-lng2) \/ 360), 2)));\n    end if;\n\n    RETURN distance;\nEND$\nDELIMITER ;<\/pre>\n<pre><\/pre>\n<pre><\/pre>\n<pre>\u63a5\u4e0b\u6765\uff0c\u5c31\u662f\u8fd0\u7528\u8fd9\u4e2afunction\u8ba1\u7b97\u8ddd\u79bb\u4e86\u3002\n\u4e3a\u4e86\u63d0\u9ad8\u6548\u7387\uff0c\u5728\u8ba1\u7b97\u8ddd\u79bb\u65f6\u9996\u5148\u901a\u8fc7\u7ecf\u5ea6\u548c\u7eac\u5ea6\u8fc7\u6ee4\uff0c\u7136\u540e\u518d\u901a\u8fc7\u8ddd\u79bb\u8fc7\u6ee4\uff0c\u56e0\u4e3a\u5982\u679c\u8ba1\u7b97\u6240\u6709\u8bb0\u5f55\u7684\u8ddd\u79bb\u6bd5\u7adf\u4e0d\u662f\u5f88\u9ad8\u6548\u7684\u505a\u6cd5\u3002<\/pre>","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u7ae0\u4e3b\u8981\u89e3\u51b3\u6570\u636e\u5e93\u5982\u679c\u5b58\u6709\u7ecf\u7eac\u5ea6\uff0c\u83b7\u53d6\u4e00\u5b9a\u8ddd\u79bb\u7684\u8bb0\u5f55\u6570 \u9996\u5148\u6211\u4eec\u5728mysql\u5efa\u7acb\u4e00\u4e2a\u53ef\u91cd\u590d\u4f7f\u7528\u7684\u8ba1\u7b97\u4e24\u4e2a\u5750\u6807\u7ecf\u7eac\u5ea6\u7684Function DELIMITER $ DROP FUNCTION IF EXI&#46;&#46;&#46;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-688","post","type-post","status-publish","format-standard","hentry","category-other"],"_links":{"self":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/688","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/comments?post=688"}],"version-history":[{"count":3,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/688\/revisions"}],"predecessor-version":[{"id":691,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/688\/revisions\/691"}],"wp:attachment":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/media?parent=688"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/categories?post=688"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/tags?post=688"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}