mysql把字符串拆成多行的方法:可以利用substring_index()函數(shù)來進(jìn)行拆分,例如【substring_index(substring_index(a.chain,'_',b.topic_id 1)】。
可以利用字符串截取函數(shù)substring_index來實(shí)現(xiàn)。
(推薦教程:mysql視頻教程)
語(yǔ)法:
substring_index(str, delimiter, count)說明:
返回一個(gè) str 的子字符串,在 delimiter 出現(xiàn) count 次的位置截取。如果 count > 0,從則左邊數(shù)起,且返回位置前的子串;如果 count < 0,從則右邊數(shù)起,且返回位置后的子串。
delimiter 是大小寫敏感,且是多字節(jié)安全的。
舉例:
select substring_index(substring_index(a.chain,'_',b.help_topic_id 1),'_' ,- 1)as idfrom (select '1_11_1223_1242' as chain) a join mysql.help_topic b on b.help_topic_id <(length(a.chain) - length( replace(a.chain, '_', '') ) 1)執(zhí)行結(jié)果:
相關(guān)推薦:php培訓(xùn)