时间:2021-07-01 10:21:17 帮助过:24人阅读
$select = 't.*,(ACOS(SIN((' . $this->latitude . '* 3.1415) / 180 )
*SIN((travel_user_status.latitude * 3.1415) / 180 )
+COS((' . $this->latitude . '* 3.1415) / 180 ) *
COS((travel_user_status.latitude * 3.1415) / 180 ) *
COS((' . $this->longitude . '* 3.1415) / 180 -
(travel_user_status.longitude * 3.1415)/180 )) * 6378.137)
as distance';
$join = 'LEFT JOIN travel_user_status ON travel_user_status.userId=t.userId';
最后想变成这样:
$select = 't.*,distance($this->latitude,$this->longitude) as distance';
$join = 'LEFT JOIN travel_user_status ON travel_user_status.userId=t.userId';
这个distance就像是一个mysql函数可以直接调用
请问我该如何做呢??
下面是我使用mysql计算距离的一个sql语句,这个sql太复杂了,我想使用mysql 的存储过程或者存储函数来简化
$select = 't.*,(ACOS(SIN((' . $this->latitude . '* 3.1415) / 180 )
*SIN((travel_user_status.latitude * 3.1415) / 180 )
+COS((' . $this->latitude . '* 3.1415) / 180 ) *
COS((travel_user_status.latitude * 3.1415) / 180 ) *
COS((' . $this->longitude . '* 3.1415) / 180 -
(travel_user_status.longitude * 3.1415)/180 )) * 6378.137)
as distance';
$join = 'LEFT JOIN travel_user_status ON travel_user_status.userId=t.userId';
最后想变成这样:
$select = 't.*,distance($this->latitude,$this->longitude) as distance';
$join = 'LEFT JOIN travel_user_status ON travel_user_status.userId=t.userId';
这个distance就像是一个mysql函数可以直接调用
请问我该如何做呢??
自行查阅手册啊:http://dev.mysql.com/doc/refman/5.0/en/create-function-udf.html