gpt4 book ai didi

mysql - 比较 MySQL 中最接近的值

转载 作者:行者123 更新时间:2023-11-30 23:02:45 25 4
gpt4 key购买 nike

我试图将两个值与我的表中的值进行比较以找到最接近的值,但每次我尝试代码(见下文)时我只返回第一行

    SELECT latitude, longitude, ABS(latitude - 53.316494), ABS(longitude - -6.253541) AS distance
FROM station
ORDER BY distance
LIMIT 1;

感谢您的帮助。

最佳答案

您的查询:

SELECT latitude, longitude, ABS(latitude - 53.316494), ABS(longitude - -6.253541)
FROM station
LIMIT 1;

但是纬度和经度中的“Compare closest value in MySQL”意味着找到最接近的方式应该看起来像:

SELECT latitude, longitude, ABS(latitude - 53.316494), ABS(longitude - -6.253541)
FROM station
ORDER BY (POW((latitude - 53.316494,2) + POW((longitude - -6.253541),2)) ASC
LIMIT 1;

enter image description here

关于mysql - 比较 MySQL 中最接近的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23269709/

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