【问题标题】:The diffrence in mysql and psql syntax - finding the closest geocoordinatesmysql和mysql语法的区别——寻找最近的坐标
【发布时间】:2021-02-22 22:20:41
【问题描述】:

我找到了一个如下所示的 psql 代码:

select * from (
SELECT *,( 3959 * acos( cos( radians(6.414478) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(12.466646) ) + sin( radians(6.414478) ) * sin( radians( lat ) ) ) ) AS distance
FROM station_location
) al
where distance < 5
ORDER BY distance
LIMIT 20;

find the nearest location by latitude and longitude in postgresql

问题是我完全不明白。 之前我用mysql,语法完全不一样:

SELECT latitude, longitude, SQRT(
POW(69.1 * (latitude - [startlat]), 2) +
POW(69.1 * ([startlng] - longitude) * COS(latitude / 57.3), 2)) AS distance
FROM TableName HAVING distance < 25 ORDER BY distance;

Find nearest latitude/longitude with an SQL query

如何把这个mysql指令转换成psql,所以用户的经纬度会是startlngstartlat

【问题讨论】:

    标签: mysql postgresql geolocation coordinates psql


    【解决方案1】:

    不评论计算本身,这个到 PostgreSQL 的“端口”应该可以工作:

    select * from (select SQRT(
    POW(69.1 * (10 - 8), 2) +
    POW(69.1 * (100 - 10) * COS(10 / 57.3), 2)) AS distance
    from table) d where distance < 25 ORDER BY distance;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-02-02
      • 2021-10-28
      • 2018-06-23
      • 2014-01-17
      • 2019-07-31
      • 1970-01-01
      • 2012-06-02
      相关资源
      最近更新 更多