我想根据sqlite中的索引获取列的子字符串。例如,我有一个名为 ID 的列,如 100P_10 。我想在' _' 之后获取数字。目前我正在使用以下查询来获取此信息。但我确信这不是正确的做法。请帮我解决这个问题。
select max(CAST( (case when substr(ID,1,1) is '_' then substr(ID,1+1) when substr(ID,2,1) is '_' then substr(ID,2+1) when substr(ID,3,1) is '_' then substr(ID,3+1) when substr(ID,4,1) is '_' then substr(ID,4+1) when substr(ID,5,1) is '_' then substr(ID,5+1)when substr(ID,6,1) is '_' then substr(ID,6+1) when substr(ID,7,1) is '_' then substr(ID,7+1) else ID end) as integer)) from student
答案 0 :(得分:1)
select cast(substr(a, instr(a, '_') + 1) as integer) from A;