业务需求:购物商城查询附件店铺并且按距离由近到远排序
数据库表结构:org_lon 经度、org_lat 纬度
Mysql查询语句:6378.138= 地球半径、坐标(0.0,0.0)、单位千米
SELECT
*, FORMAT(
(
ACOS(
SIN((0.0 * PI()) / 180) * SIN((org_lat * PI()) / 180) + COS((0.0 * PI()) / 180) * COS((org_lat * PI()) / 180) * COS(
(0.0 * PI()) / 180 - (org_lon * PI()) / 180
)
) * 6378.138
) / 1000,
2
) distance
FROM
sys_organization
ORDER BY
distance ASC
运行结果