我在 double 列上使用 SQL 查询,但没有得到任何结果。
select *
from chicago_2po_4pgr
where f_estimated=38867.0150708261
我确定带有 f_estimated=38867.0150708261
的行存在。
我尝试修改查询并使用 enter link description here 中提到的解决方案但只有当我将 = 更改为 < 或 > 时它才有效。 我需要知 Prop 有此值的确切行。
请问我怎样才能得到这一行?
最佳答案
这是因为常量是数字类型——这是精确的——但列是 float 。这些可能会有一些小差异。
一种方法是将它们转换为同一类型。这可能有效:
select *
from chicago_2po_4pgr
where f_estimated = 38867.0150708261::double precision
但是,这可能无法推广。更安全的方法是:
select *
from chicago_2po_4pgr
where abs(f_estimated - 38867.0150708261) < 0.0001
或者任何合理的阈值。
最安全的方法是完全放弃 double 。将值表示为数字(首先想到的是 numeric(20, 10)
。然后您可以进行精确比较。
关于sql - 没有结果的 Where 子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51814253/