sql 根据经纬度查找附近数据

发布日期 2024-01-04

SELECT
    ROUND(
        6378.138 * 2 * ASIN(
            SQRT(
            POW( SIN(( 23.065502 * PI()/ 180-dt_lat * PI()/ 180 )/ 2 ), 2 )+ COS( 23.065502 * PI()/ 180 )* COS( dt_lat * PI()/ 180 )* POW( SIN(( 113.803962 * PI()/ 180- dt_lng * PI()/ 180 )/ 2 ), 2 )))* 1000 
    ) AS distance,
    a.id,
    a.title,
    a.price,
    a.unit,
    a.dt_lat,
    a.dt_lng 
FROM
    `cms_house` AS a 
HAVING
    distance <= 1500 
ORDER BY
    distance ASC

dt_latdt_lng 为表中 经纬度字段