比如有一个字段 “Code”,里面存储了这么几个值:
我需要查询出后四位数字为0的记录:10000、20000、30000,对应的SQL语句该怎么写呀?
我要的是精确查找,不要模糊查找。求答案!!!
使用SQL的substr函数即可。
该方式格式如下:
substr( string, start_position, [ length ] );
string:源字符串;
start_position:提取的位置,字符串中第一个位置始终为1;
[ length ]:提取的字符数,如果省略,substr将返回整个字符串;
函数功能:截取函数,可以实现提取字符串中指定的字符数;
针对本例举例说明:
select * from 表名 where substr([D],1,2)=“10”
语句功能说明:从指定表中查询D字段第1、2个字符为“10的记录”。
or
select *直接求模取余,能整除10000的就是尾数就是4个0