码迷,mamicode.com
首页 > 其他好文 > 详细

help_topic表,以字符拆分,一行转多行

时间:2019-07-31 12:49:15      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:拆分   一个   dex   image   topic   rom   select   col   print   

  help_topic表是数据库mysql下的一个表

  技术图片

    SUBSTRING_INDEX(s, delimiter, number)    

     返回从字符串 s 的第 number 个出现的分隔符 delimiter 之后的子串。   

  1. 如果 number 是正数,返回第 number 个字符左边的字符串。
    SELECT SUBSTRING_INDEX(‘a*b*c*d*e‘,‘*‘,3);    ---- a*b*c
  2. 如果 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);

   技术图片

help_topic表,以字符拆分,一行转多行

标签:拆分   一个   dex   image   topic   rom   select   col   print   

原文地址:https://www.cnblogs.com/likaixin/p/11271756.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!