我有一个带有记录的产品表(产品):
id name
1 1969-1972 Chevrolet Small Block
2 1971-1975 Chevrolet Small Block Fan Shroud
3 1964 Chevrolet Bumper Kit Complete
4 Chevrolet Clutch And Brake Pedal Assembly
...
现在,我要使请求结束提取前四个数字作为开始日期,并将6到9之间的字符作为结束日期。
因此结果表将是:
id name start end
1 1969-1972 Chevrolet Small Block 1969 1972
2 1971-1975 Chevrolet Small Block Fan Shroud 1971 1975
3 1964 Chevrolet Bumper Kit Complete 1964 null
4 Chevrolet Clutch And Brake Pedal Assembly null null
...
谢谢!
最佳答案
1. LEFT(name , 4) as start;
2. CAST(SUBSTRING(name, 6, 4) AS UNSIGNED) as end;
关于php - MySQL请求|从表中的字符串获取数字,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50534712/