sql语句查询String类型字段小于10的怎么查

img


我想查syl小于10的,一共是13条小于10的,但是syl这个字段是varchar类型的,
①我这样写

img


只查出来8条,查不全。
②我这样写,不知道怎么转换成int

img


怎么办啊,怎么查


select * from D_Info where syl is not null and syl <> '' CAST ( syl AS DECIMAL(18,4)) < 10

字符串类型比较大小最简单的办法就是+0.类似:

select * from table where num+0 < 10

如有帮助,欢迎采纳!

SQL Server使用以下语句:

select * from table where convert(decimal(6, 2), syl)<10

尝试转为float类型,测试可行,但过长的值可能会有精度丢失

select * from tmp.tmp_20220729 where cast(syl as float) < 10;

img

select * from D_Info where convert(syl, decimal(12,2)) < 10 and syl <> '' and syl is not null;

select cast('123' as signed) from dual; 字符转数字

select * from D_Info where syl is not null and syl < 10


select truncate(cast(abs('414.55555') as decimal(15,3)),3);

字符串转int

来晚了,遇到这类问题可以用cast强转

转成数值类型(float、decimal)再进行比较。