gpt4 book ai didi

Mysql为什么12.3 < 12.3是真的

转载 作者:行者123 更新时间:2023-11-29 01:16:24 24 4
gpt4 key购买 nike

我有一张 table

-------OT-----------
- id - INT -
- from_time - FLOAT-
- to_time - FLOAT-
--------------------

保存值(value)

- id - from_time -- to_time --
-------------------------
- 1 - 8.3 -- 12.3 --
-------------------------

我的 SQL 查询

SELECT * FROM (`OT` as wt) WHERE ( (12.3 < wt.to_time) );

预期它没有返回任何记录。但它实际上返回了记录 id = 1。

我尝试过使用 0.3 到 15.3,它是相同的,但使用 16.6 时它不返回任何记录。我的 MySQL 版本是 5.6.23。

请帮助我,为什么会这样?

最佳答案

浮点精度不是精确的科学。您应该使用 DECIMAL 数据类型而不是 FLOAT

引用:https://dev.mysql.com/doc/refman/5.0/en/problems-with-float.html

关于Mysql为什么12.3 < 12.3是真的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30221653/

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