如何从字符串字段mysql获取数字

时间:2014-09-30 20:49:44

标签: mysql

我的字段有值类型store878。我想从select语句中获得878。如何从select语句中获取该数字

 select 
     store,
     address 
 from 
     detail, 
     store_number 
 where 
     store (here i would like to have number) =  store_mumber.id 

1 个答案:

答案 0 :(得分:1)

我还没有对此进行测试以确保有效:

SELECT store, address 
FROM detail d
INNER JOIN store_number s
   ON CAST(SUBSTRING(d.store, LOCATE('%[0-9]%', d.store)) AS int) =  s.id 

但您应该考虑更改数据库的结构。