select unitname,unitcode from g3_unit where unitcode=substr('1002',1,3);
这个是数据库截取数字串的前三位 获得的unicode是100
我想知道怎么能把后三位截掉,只要前面的数字串 如上例获得1
我的数据库里的unitcode不只是由1002 还有 12345 123456等类似的数据
刚刚回答错了。select unitname,unitcode from g3_unit where unitcode=substr(你的字段,1,length(你的字段)-3)
select unitname,unitcode from g3_unit where unitcode=substr('1002',-1,3);
select left(unitcode ,CHAR_LENGTH(unitcode )-3) as unitcode , unitname from g3_unit
前面那个有误
select unitname,unitcode from g3_unit where unitcode=substr(你的字段,length()-3,3)
length(你的字段)