TOC

MySQL 的浮点型精度问题

查询条件中的浮点型精度问题

MySQL [test]> select * from user_priority where priority = 0.0001 and expire_time = '2024-05-06 12:00:00';
Empty set (0.075 sec)

MySQL [test]> select * from user_priority where priority < 0.0001 and expire_time = '2024-05-06 12:00:00' limit 10;
+----+---------+----------+---------------------+--------+
| id | user_id | priority | expire_time         | remark |
+----+---------+----------+---------------------+--------+
|  1 |   19003 |   0.0001 | 2024-05-06 12:00:00 | NULL   |
|  2 |   19008 |   0.0001 | 2024-05-06 12:00:00 | NULL   |
|  3 |   19009 |   0.0001 | 2024-05-06 12:00:00 | NULL   |
|  4 |   19011 |   0.0001 | 2024-05-06 12:00:00 | NULL   |
|  5 |   19015 |   0.0001 | 2024-05-06 12:00:00 | NULL   |
|  6 |   19016 |   0.0001 | 2024-05-06 12:00:00 | NULL   |
|  7 |   19018 |   0.0001 | 2024-05-06 12:00:00 | NULL   |
|  8 |   19019 |   0.0001 | 2024-05-06 12:00:00 | NULL   |
|  9 |   19021 |   0.0001 | 2024-05-06 12:00:00 | NULL   |
| 10 |   19023 |   0.0001 | 2024-05-06 12:00:00 | NULL   |
+----+---------+----------+---------------------+--------+
10 rows in set (0.707 sec)
如果你有魔法,你可以看到一个评论框~