可以利用字符串截取函数SUBSTRING_INDEX来实现。
(推荐教程:mysql视频教程)
语法:
SUBSTRING_INDEX(str, delimiter, count)
说明:
返回一个 str 的子字符串,在 delimiter 出现 count 次的位置截取。如果 count > 0,从则左边数起,且返回位置前的子串;如果 count < 0,从则右边数起,且返回位置后的子串。
delimiter 是大小写敏感,且是多字节安全的。
举例:
SELECT substring_index(substring_index(a.chain,'_',b.help_topic_id + 1),'_' ,- 1)AS ID FROM (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)
执行结果:
Copyright © 2019- huatuo0.cn 版权所有 湘ICP备2023017654号-2
违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务