简体   繁体   English

仅选择数值

[英]Select only numeric value

I have a table structure like below. 我有一个像下面这样的表结构。

id            version     REQ_REF_ID
 3              1.2            6
 2              1.1            6
 1               1             6

My query is below 我的查询如下

Select * from XYZ where REQ_REF_ID = 6606 order by version desc FETCH FIRST 2 ROWS ONLY

It gives me the latest 2 rows which id is 3 and 2. 它给了我最新的2行,id为3和2。

But I want to get only those two row where version number is integer, not having decimal values. 但是我只想获取version号是整数而不是十进制值的那两行。

In this case I want to get the row which id is 1. 在这种情况下,我想获取id为1的行。

You can check against ROUND function to get integer values 您可以检查ROUND函数以获取整数值

and ROUND(version) = version

ROUND returns n rounded to integer places to the right of the decimal point. ROUND返回将n舍入到小数点右边的整数位。

您也可以使用TRANSLATE

 where translate(VERSION, '?1234567890', '?') is null

you can check like 你可以检查像

and (version)%1 = 0

% by 1 will give you decimal parts if any %by 1将为您提供小数部分

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

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