我对一个视图运行一个非常简单的查询,它使用一个值,但不能与所有其他值一起使用。我试图从视图中选择具有不同索引值的行仅索引1.5返回结果
以下是视图表的示例
我有这个视图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)
答案 0 :(得分:1)
浮动的危险(具有未定义的精度和比例)
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 |
+----+------+--------+------+-------+-------+-------+---------+----------+
答案 1 :(得分:1)
尝试CAST
SELECT * FROM easylens WHERE CAST(`index` as DECIMAL) = CAST(1.6 as DECIMAL);