gpt4 book ai didi

MySQL St_distance_Sphere 函数

转载 作者:行者123 更新时间:2023-11-29 07:18:44 29 4
gpt4 key购买 nike

我正在尝试查询一个小表以查找表中输入坐标点 1 公里以内的所有记录。表中的每条记录都有一个带有相应点的“Lat”和“Long”列。我的查询是

var sql = `SELECT * FROM GeoTest WHERE st_distance_sphere(POINT(-100,35),POINT(Long,Lat)) <= 1000`

error 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'Long,Lat)) <= 1000\'

表格中的数据

id        Lat                 Long

1 30.5092060000000000 -97.6046760000000000
2 31.1310390000000000 -97.7805610000000000

我不知道如何使用所选行返回的经纬度来比较距离,如果在1Km以内则只返回记录。如何将记录中的 Long 和 Lat 字段替换为 st_distance_sphere 函数?我确定我在这里遗漏了一些非常简单的东西。感谢您帮助这个 SQL 菜鸟!

最佳答案

使用它适用于 5.7 和 8.0

   Select st_distance_sphere(POINT(-100,35),
POINT ( `Long` , `Lat`) ) From GeoTest;

关于MySQL St_distance_Sphere 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57682987/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com