简体   繁体   English

删除基于Mysql / PHP中的float列的行?

[英]Deleting a row based on a float column in Mysql/PHP?

This 这个

DELETE FROM `z_ratings` 
WHERE `score` = '5.4' 
  AND `media_id` = '242' 
  AND `user_id` = '1'

will not delete the following row: 不会删除以下行:

在此处输入图片说明

Can anybody explain why? 有人可以解释为什么吗?

(I'm assuming the issue is with the float since both other columns are integers) (我假设问题出在浮点数上,因为其他两列都是整数)

The problem is the floating point column. 问题是浮点列。 You can review the issues with this representation and comparisons. 您可以使用此表示形式和比较来查看问题。 One place to start is the documentation . 一个开始的地方是文档

Great, we know it doesn't work. 太好了,我们知道这行不通。 More importantly, what can you do? 更重要的是,您能做什么?

Probably the most accurate solution is to switch to decimal, say decimal(5, 1) for the column. 可能最准确的解决方案是切换到十进制,例如将列设置为decimal(5, 1) Then, this shouldn't be a problem. 然后,这应该不是问题。

Alternatively, use abs() and difference for a fuzzy comparison: 或者,使用abs()和Difference进行模糊比较:

abs(score - 3.4) < 0.0001

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM