我有一个表Splidata 和列名称是ID,产品,成本,备注
产品列包含以下字符串。
BROCHURE ( SIZE:11x17 FOLDING:Double Gate Fold PAPER:100lb Gloss Book with Aqueous Coating (C2S) COLOR:full/full TURNAROUND:Standard )
现在我想以下面的格式从mysql数据库中获取时显示数据。 (对于产品列)。其余的列数据也在那里。
+------------+------------------+--------------------------------------------+--------------------------------+
| Size | Folding | Paper | COLOR |
+------------+------------------+--------------------------------------------+--------------------------------+
| 11x17 | Double Gate Fold | 100lb Gloss Book with Aqueous Coating (C2S)| full/full TURNAROUND:Standard |
+------------+------------------+--------------------------------------------+--------------------------------+
答案 0 :(得分:0)
你可以使用mysql SUBSTRING_INDEX
http://www.w3resource.com/mysql/string-functions/mysql-substring_index-function.php
例如,如果要提取大小,请使用
select
SUBSTRING_INDEX(SUBSTRING_INDEX(product, 'SIZE:', -1) , ' ' ,1) AS size
,SUBSTRING_INDEX(SUBSTRING_INDEX(product, 'FOLDING:', -1) , 'PAPER:' ,1) AS Folding
,SUBSTRING_INDEX(SUBSTRING_INDEX(product, 'PAPER:', -1) , 'COLOR:' ,1) AS PAPER
,SUBSTRING_INDEX(SUBSTRING_INDEX(product, 'COLOR:', -1) , ' )' ,1) AS COLOR
from Splidata