gpt4 book ai didi

mysql - Mysql View 查询无法正常工作

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

我在一个 View 上运行一个非常简单的查询,它适用于一个值,不适用于所有其他值。我正在尝试从 View 中选择具有不同索引值的行,仅索引 1.5 返回结果

以下是 View 表的示例

我有这个View easylens

select * from easylens

+---+----+------+----+-----+-----+-----+-------+--------+
|id |type|design|name|brand|index|color|coating|material|
+---+----+------+----+-----+-----+-----+-------+--------+
| 1 | sv |aase |nel |hoya | 1.5|292 |ar |plastic |
+---+----+------+----+-----+-----+-----+-------+--------+
| 2 | sv |base |tel |zeri | 1.5|293 |ar |plastic |
+---+----+------+----+-----+-----+-----+-------+--------+
| 3 | sv |case |fel |essi | 1.5|294 |ar |plastic |
+---+----+------+----+-----+-----+-----+-------+--------+
| 4 | sv |dase |gel |hoya | 1.6|293 |ar |plastic |
+---+----+------+----+-----+-----+-----+-------+--------+
| 5 | sv |fase |rel |essi | 1.6|293 |ar |plastic |
+---+----+------+----+-----+-----+-----+-------+--------+
| 6 | sv |gase |mel |hoya | 1.6|292 |ar |plastic |
+---+----+------+----+-----+-----+-----+-------+--------+

当我运行时

select * from easylens where `index`=1.5

我明白

+---+----+------+----+-----+-----+-----+-------+--------+
|id |type|design|name|brand|index|color|coating|material|
+---+----+------+----+-----+-----+-----+-------+--------+
| 1 | sv |aase |nel |hoya | 1.5|292 |ar |plastic |
+---+----+------+----+-----+-----+-----+-------+--------+
| 2 | sv |base |tel |zeri | 1.5|293 |ar |plastic |
+---+----+------+----+-----+-----+-----+-------+--------+
| 3 | sv |case |fel |essi | 1.5|294 |ar |plastic |
+---+----+------+----+-----+-----+-----+-------+--------+

但是当我运行时

select * from easylens where `index`=1.6

我明白

MySQL returned an empty result set (i.e. zero rows). (Query took 0.0002 sec)

最佳答案

float 的危险(未定义的精度和小数位数)

SELECT * FROM easylens WHERE `index` = 1.6000000238418578;
+----+------+--------+------+-------+-------+-------+---------+----------+
| id | type | design | name | brand | index | color | coating | material |
+----+------+--------+------+-------+-------+-------+---------+----------+
| 4 | sv | dase | gel | hoya | 1.6 | 293 | ar | plastic |
| 5 | sv | fase | rel | essi | 1.6 | 293 | ar | plastic |
| 6 | sv | gase | mel | hoya | 1.6 | 292 | ar | plastic |
+----+------+--------+------+-------+-------+-------+---------+----------+

关于mysql - Mysql View 查询无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25763495/

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