sql 获取两点距离

select * from (select 
(2*6378137*SQRT((sin(((a.latitude*PI()/180.0)-b.lat1)/2.0))* (sin(((a.latitude*PI()/180.0)-b.lat1)/2.0))+COS(b.lat1)*COS(a.latitude*PI()/180.0)*((sin(((a.longitude*PI()/180.0)-b.long1)/2.0)))*((sin(((a.longitude*PI()/180.0)-b.long1)/2.0))))) as dis

from user_latitude_longitude a,
(SELECT (b.latitude*PI()/180.0) as lat1,(b.longitude*PI()/180.0) as long1 from user_latitude_longitude b where b.userId=28) b
where a.userId !=  28 ) f where dis >500 order by dis desc 

你可能感兴趣的:(sql)