如何在IBM-I(as400)中运行的IBM DB2数据库的SQL中过滤小数位

问题描述 投票:0回答:2

我有一个文件(或表),假设 Table1 由数字字段 Num1 组成,该字段的值类似于 1001.001、1001.000、1001.002 等。我想编写一个 SQL 查询,从该字段中过滤小数点位置不为 000 的值。SQL 将选择记录 1001.001、1001.002,但会过滤掉 1001.000。

有人可以建议如何执行此操作吗?此查询需要在 IBM DB2 上运行,而 IBM DB2 在 IBM AS400 (IBM - I) 系统中运行。

sql db2 ibm-midrange rpgle rpg
2个回答
2
投票

您可以从数字中减去整数部分,如果整数部分可以容纳 int 或 bigint ,则测试结果为 0 :

with table1 (num1) as (
  values
  1001.001,
  1001.000,
  1001.002
)
select * from table1 where num1 - bigint(num1) = 0
NUM1
1001.000

小提琴


0
投票

round 功能也可以使用。将四舍五入到小数点后零位的数字与其本身进行比较。

with table1 (num1) as (
  values
  1001.001,
  1001.000,
  1001.002
)
select  num1, round(num1,0) rounded
from  table1
where  round(num1,0) <> num1 ;
© www.soinside.com 2019 - 2024. All rights reserved.