行业代码数据格式如下

行业代码获取最近代码

 

select t.*,length(code1||code2||code3||code4) as templen from industry t

行业代码获取最近代码

可发现templen跟code关系

templen value
1 code1
3 code2
6 code3
10 code4

 

 

最终sql

select t.*,
case length(code1||code2||code3||code4) 
  when 1 then code1
  when 3 then code2
  when 6 then code3
  else code4
end as industry_code
from industry t

查询结果

行业代码获取最近代码

 

相关文章:

  • 2021-07-25
  • 2021-11-16
  • 2021-06-11
  • 2022-12-23
  • 2022-12-23
  • 2021-12-07
  • 2021-10-03
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-13
  • 2021-12-15
  • 2022-12-23
  • 2021-03-31
相关资源
相似解决方案