数据库
首页 > 数据库> > mysql-不能正常工作

mysql-不能正常工作

作者:互联网

我的表格具有存储为文本的纬度和经度值.对于纬度和经度值分别为的记录:

+------+-------------------+--------------------+
| Name |        Lat        |        Long        |
+------+-------------------+--------------------+
| ABC  | 32.74943951828427 | -97.33141142455626 |
+------+-------------------+--------------------+

我的SQL查询出来像:

SELECT * FROM Incident I WHERE
(I.Lat BETWEEN '32.740446302225' AND '32.758432734343') 
AND 
(I.Long BETWEEN '-97.342104340547' AND '-97.320718508566')
LIMIT 5

但这导致返回0行.该表中确实存在“ ABC”记录,但是我不知道为什么它没有提取它.不能将字符串作为浮点数进行比较吗?

解决方法:

发生这种情况是因为您将它们用作字符串.

BETWEEN的语法是-> value在small_val和big_val之间,但由于您将它们用作字符串,因此-97.34 ..比-97.32大,因此它不起作用.

尝试:

(CAST(I.Lat as UNSIGNED) BETWEEN 32.740446302225 AND 32.758432734343) 
AND 
(CAST(I.Long as UNSIGNED) BETWEEN -97.342104340547 AND -97.320718508566)

在字符串类型的列中存储数值是错误的!我强烈建议您将其更改为“数值”类型,因为它应该是.

标签:geocoding,sql,mysql
来源: https://codeday.me/bug/20191026/1938587.html