其中M中数据如M(1)=mm001
M(2)=mm002
M(3)=mm003
......
类型为varchar
现在想做个循环,将M中mm后面的数字部分提取出来最大值,附给num,类型为integer
大家看看我这个语句可以吗?
SELECT MAX(CAST(SUBSTRING(M,2,9) AS INTEGER)) AS NUM FROM RUNCARD
感觉其中的类型转换有点乱,请高手指教,谢谢,急!!!
4 个解决方案
#1
SELECT MAX(CAST(SUBSTRING(M,3,9) AS INT)) AS NUM FROM RUNCARD
#2
对的,coolingpipe的,没错
#3
这样也可以:)
SELECT MAX(cast(REPLACE(M,'mm','') AS INT)) AS NUM FROM RUNCARD
SELECT MAX(cast(REPLACE(M,'mm','') AS INT)) AS NUM FROM RUNCARD
#4
这样也可以
select cast(right((select max(m) from runcard),3) as int) as num
select cast(right((select max(m) from runcard),3) as int) as num
#1
SELECT MAX(CAST(SUBSTRING(M,3,9) AS INT)) AS NUM FROM RUNCARD
#2
对的,coolingpipe的,没错
#3
这样也可以:)
SELECT MAX(cast(REPLACE(M,'mm','') AS INT)) AS NUM FROM RUNCARD
SELECT MAX(cast(REPLACE(M,'mm','') AS INT)) AS NUM FROM RUNCARD
#4
这样也可以
select cast(right((select max(m) from runcard),3) as int) as num
select cast(right((select max(m) from runcard),3) as int) as num