美文网首页
【MySQL】每日一题2020-02-25

【MySQL】每日一题2020-02-25

作者: 每天要读书的Claire | 来源:发表于2020-02-25 19:50 被阅读0次
    create table t_0225 (hobby varchar(50))ENGINE=INNODB DEFAULT CHARSET=utf8;
    insert into t_0225 values('篮球');
    insert into t_0225 values('足球');
    insert into t_0225 values ('羽毛球');
    insert into t_0225 values('乒乓球');
    
    mysql> select group_concat(hobby) as hobby from t_0225;
    +-----------------------------------+
    | hobby                             |
    +-----------------------------------+
    | 篮球,足球,羽毛球,乒乓球           |
    +-----------------------------------+
    1 row in set (0.00 sec)
    
    mysql> select substring_index(substring_index(hobby,',',help_topic_id+1),',',-1) as hobby from t_0225 left join mysql.help_topic on (length(hobby)-length(replace(hobby,',',''))+1)>help_topic_id;
    +-----------+
    | hobby     |
    +-----------+
    | 篮球      |
    | 足球      |
    | 羽毛球    |
    | 乒乓球    |
    +-----------+
    4 rows in set (0.00 sec)

    相关文章

      网友评论

          本文标题:【MySQL】每日一题2020-02-25

          本文链接:https://www.haomeiwen.com/subject/phgfchtx.html