我正在尝试拆分以下字符串 -
Reference 1 Drug Name: Lisdexamphetamine, Strength: 30mg, Form: capsule, Quantity: 21 Drug Name: Lisdexamphetamine, Strength: 50mg, Form: capsule, Quantity: 21 Drug Name: Fentanyl, Strength: 100mcg, Form: patches, Quantity: 5 Drug Name: Durogesic , Strength: 25mcg, Form: patches, Quantity: 5 Drug Name: Durogesic, Strength: 75mcg, Form: patches, Quantity: 10 Drug Name: Durogesic, Strength: 100mcg, Form: patches, Quantity: 15 Drug Name: Oxycodone, Strength: 20mg, Form: tablet, Quantity: 84
单个列,例如参考|药物名称|力量|形式|量
正如您所看到的,每个名字后面都有一个冒号。
这是我到目前为止所尝试的:
SELECT reference, email, SUBSTRING_INDEX(SUBSTRING_INDEX(drugs,',',1),':',-1) AS Drug,
SUBSTRING_INDEX(SUBSTRING_INDEX(drugs,',',2),':',-1) AS Strength,
SUBSTRING_INDEX(SUBSTRING_INDEX(drugs,',',3),':',-1) AS Form
,
SUBSTRING_INDEX(SUBSTRING_INDEX(drugs,',',5),':',-1) AS Quantity
FROM CD2015_destructions
但每个参考编号只返回1行,而可能有多个
当前声明给我:
Reference | Drug Name | Strength | form | Quantity
1 |Paracetamol|20MG | Tablet | 5
2 |Methadone | 15MG | Liquid | 10
3 |Pethadine | 15MG | Liquid | 12
等。
但如果我的参考号码有多种药物,它就不会显示下一行
Reference | Drug Name | Strength | form | Quantity
1 |Paracetamol | 20MG | Tablet | 5
1 |Oxyconton | 15MG | Liquid | 10
1 |Methadone | 25MG | capsule | 10