help_topic表是數據庫mysql下的一個表
SUBSTRING_INDEX(s, delimiter, number)
返回從字符串 s 的第 number 個出現的分隔符 delimiter 之后的子串。
- 如果 number 是正數,返回第 number 個字符左邊的字符串。
SELECT SUBSTRING_INDEX('a*b*c*d*e','*',3); ---- a*b*c
- 如果 number 是負數,返回第(number 的絕對值(從右邊數))個字符右邊的字符串。
SELECT SUBSTRING_INDEX('a*b*c','*',-1); ---- c
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX('a*b*c*d*e','*',3),'*',-1); ---- c
示例:
select a.id, a.username, substring_index(substring_index(a.course, '|', b.help_topic_id + 1), '|', -1) course from student a JOIN mysql.help_topic b ON b.help_topic_id < (length(a.course) - length(REPLACE(a.course, '|', '')) + 1);