location字段为point类型的空间坐标
SELECT
id,
name,
address,
x(location) as 经度,
Y(location) as 纬度,
ROUND(
6378.138 * 2 * ASIN(
SQRT(
POW(
SIN(
(
40.0497810000 * PI() / 180 - lat * PI() / 180
) / 2
),
2
) + COS(40.0497810000 * PI() / 180) * COS(lat * PI() / 180) * POW(
SIN(
(
116.3424590000 * PI() / 180 - lng * PI() / 180
) / 2
),
2
)
)
) * 1000
) AS 距离
FROM
oc_district
HAVING
距离 < 400000
ORDER BY
距离 ASC