12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
ADADADADAD
mysql数据库 时间:2024-11-29 10:11:52
作者:文/会员上传
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
mysql把字符串拆成多行的方法:可以利用SUBSTRING_INDEX()函数来进行拆分,例如【substring_index(substring_index(a.chain,'_',b.topic_id + 1)】。可以利用字符串截
以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。
mysql把字符串拆成多行的方法:可以利用SUBSTRING_INDEX()函数来进行拆分,例如【substring_index(substring_index(a.chain,'_',b.topic_id + 1)】。
可以利用字符串截取函数SUBSTRING_INDEX来实现。
语法:
SUBSTRING_INDEX(str, delimiter, count)
说明:
返回一个 str 的子字符串,在 delimiter 出现 count 次的位置截取。如果 count > 0,从则左边数起,且返回位置前的子串;如果 count < 0,从则右边数起,且返回位置后的子串。
delimiter 是大小写敏感,且是多字节安全的。
举例:
SELECTsubstring_index(substring_index(a.chain,'_',b.help_topic_id + 1),'_' ,- 1)AS IDFROM(select '1_11_1223_1242' as chain) aJOIN mysql.help_topic b ON b.help_topic_id <(length(a.chain) - length( replace(a.chain, '_', '')) + 1)
执行结果:
11-20
11-19
11-20
11-20
11-20
11-19
11-20
11-20
11-19
11-20
11-19
11-19
11-19
11-19
11-19
11-19