码迷,mamicode.com
首页 > 数据库 > 详细

【转】mysql用sql实现split函数

时间:2019-07-30 15:30:35      阅读:514      评论:0      收藏:0      [点我收藏+]

标签:tps   mic   arch   div   淘宝   any   engine   company   sub   

关键词:mysql split

mysql根据逗号将一行数据拆分成多行数据
1、原始数据演示

技术图片

 


2、处理结果演示

技术图片

 


3、sql语句

SELECT a.id
    , a.NAME
    , substring_index(substring_index(a.shareholder, ‘,‘, b.help_topic_id + 1), ‘,‘, - 1) AS shareholder

FROM company a

INNER JOIN mysql.help_topic b
    ON b.help_topic_id < (length(a.shareholder) - length(REPLACE(a.shareholder, ‘,‘, ‘‘)) + 1)


4、附录
基本表建立语句

CREATE TABLE `company` (
`id` int(20) DEFAULT NULL,
`name` varchar(100) DEFAULT NULL,
`shareholder` varchar(100) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `company` VALUES (‘1‘, ‘阿里巴巴‘, ‘马云‘);
INSERT INTO `company` VALUES (‘2‘, ‘淘宝‘, ‘马云,孙正义‘);


原文:https://blog.csdn.net/WY18334783911/article/details/83379450

【转】mysql用sql实现split函数

标签:tps   mic   arch   div   淘宝   any   engine   company   sub   

原文地址:https://www.cnblogs.com/gered/p/11270188.html

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