为什么在运算符中无法正常工作,在MySQL查询中具有浮点值?
我正在使用 MySQL 查询。在工作时,我遇到了包含 IN 运算符的查询问题。当 IN 与整数值一起使用时,它可以正常工作。但是,当 IN 与浮点值一起使用时,不会出现正确的输出。如果 WHERE 子句用于使用 IN 运算符检查两个值,则在数据类型为 float 的值的情况下,它仅在少数情况下检查并返回查询中给定值中第一个出现在表中的值。 为什么会出现这种情况以及如何解决?
假设有一个表 customer ,其属性 customer_id int(4)
customer_id |
---|
3001 |
3003 |
3007 |
3008 |
3009 |
3012 |
假设有一个查询:
select customer_id from customer where customer_id in (3007,3008,3009);
在这里它工作正常并输出包含指定属性下的这些值的记录
但是当存在 float 数据类型的值时会出现问题
有一个带有属性 purch_amt float(6,2)
purch_amt |
---|
110.5 |
948.5 |
的表 orders 1983.43 |
如果查询是:
select purch_amt from orders where purch_amt in(948.5,110.5);
它返回本例表中的记录。
如果查询是:
select purch_amt from orders where purch_amt in(948.5,1983.43);
对于这种情况,它仅返回包含表中较早出现的值的记录。 为什么会发生这种情况以及我们如何解决这个问题?
I was working with MySQL Queries. While working I am having problem with the queries containing IN operator. When IN is used with integer values it works properly. But when IN is used with floating-point values proper output is not coming. If WHERE clause is used to check two values with IN operator, in case of values with datatype float it only checks and returns the value which appears first in the table from the given values in query for few cases.
Why this occurs and how to solve this?
Let there is a table customer with attribute customer_id int(4)
customer_id |
---|
3001 |
3003 |
3007 |
3008 |
3009 |
3012 |
Lets say there is query:
select customer_id from customer where customer_id in (3007,3008,3009);
Here it works fine and outputs the records containing these values under the specified attribute
But when there are values of float datatype a problem occurs
There is a table orders with attribute purch_amt float(6,2)
purch_amt |
---|
110.5 |
948.5 |
1983.43 |
If the query is:
select purch_amt from orders where purch_amt in(948.5,110.5);
It returns the records from the table for this case.
If the query is:
select purch_amt from orders where purch_amt in(948.5,1983.43);
It only returns the record containing the value which is present earlier in the table for this case.
Why is this occuring and how can we solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论