如果是select查询做显示的话
select code,
name,
case when length(code) =3 then 1
when length(code)=6 then 2
when length(code)=9 then 3
end id
from table;
如果是要插入的话
update table set id =(
case when length(code) =3 then 1
when length(code)=6 then 2
when length(code)=9 then 3
end)
update 表名
set id=(case when length(code) = 3 then
1
when length(code) = 6 then
2
when length(code) = 9 then
3
end)
select case when length(code) = 3 then 1 when length(code) = 6 then 2 when length(code) = 9 then 3 end ID
from tab
是这样吗?