mysql - postgres 查询不匹配负 double 值

标签 mysql postgresql floating-point numeric

我正在使用 psql (9.1.3)。我有一张 table (比如说)A

A 有两列:

a_id:整数

customer_pay: double

I have these values in the table.

 a_id      | customer_pay |    

--------------------+--------------+

   1733684 |       -264.6 | 
   1723382 |      -314.84 |
   1728106 |        50.55 |
   1741636 |       -264.6 |  (4 rows)

但是当我这么做的时候

select a_id from A where customer_pay = -264.6;

什么也没有

我尝试了所有可能的精度变化,例如 -264.60、-264.00 等。 此查询对于 +264.6 准确有效。 我应该如何选择负 double 类型的值。

感谢您的帮助。

最佳答案

select a_id
from a
where round(customer_pay::numeric, 2) = -264.6

From the manual:

Calculations with numeric values yield exact results where possible, e.g. addition, subtraction, multiplication. However, calculations on numeric values are very slow compared to the integer types, or to the floating-point types described in the next section.

关于mysql - postgres 查询不匹配负 double 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40399476/

相关文章:

php - 合并 2 个 mysql 结果的输出

python - 从二维列表中删除重复项( float )

c++ - literal double 到 float 的转换是否等于 float literal?

c++ - 双倍与 float

sql - 需要有关 SQL 查询的帮助

php - 在PHP中计算两个X,Y坐标之间的距离

MySQL select 出现重复结果的问题

sql - 在 JSONB 字段上使用 Like 进行查询

postgresql - Tsquery返回完全匹配的关键字

python - Postgresql - PSql 速查表