使用 SQL 查询小数点后十位以上的数字
Using SQL to query numbers that have more than tenths decimal place
我有一个包含数字的文本字段。其中一些数字在小数点后有两位数,而另一些只有一位。
有没有SQL表达式只查询百分位的数字?
我的最终目标是使用"round"函数将这些孤立的数字四舍五入到十分位。
使用的 RDBMS:sql-服务器
您可以使用 charindex
和 reverse
来做到这一点。
select val
from tbl
where charindex('.', reverse(val)) = 3
演示
declare @tbl table(val varchar(50))
insert into @tbl select '11.02'
insert into @tbl select '411.0'
insert into @tbl select '11.44'
insert into @tbl select '1144.03'
insert into @tbl select '1441.5'
select val
from @tbl
where charindex('.', reverse(val)) = 3
output:
11.02
11.44
1144.03
我有一个包含数字的文本字段。其中一些数字在小数点后有两位数,而另一些只有一位。
有没有SQL表达式只查询百分位的数字?
我的最终目标是使用"round"函数将这些孤立的数字四舍五入到十分位。
使用的 RDBMS:sql-服务器
您可以使用 charindex
和 reverse
来做到这一点。
select val
from tbl
where charindex('.', reverse(val)) = 3
演示
declare @tbl table(val varchar(50))
insert into @tbl select '11.02'
insert into @tbl select '411.0'
insert into @tbl select '11.44'
insert into @tbl select '1144.03'
insert into @tbl select '1441.5'
select val
from @tbl
where charindex('.', reverse(val)) = 3
output:
11.02
11.44
1144.03