MySql 5.6.33 一列切割成多行

目前没有在官网文档上找到直接的函数或方法能够将一列切割成多行。利用搜索引擎找到了这种方法个人记录备忘一下。

SELECT user_id, user_scope FROM ty_user_info WHERE user_id = 7958;	
	
SELECT
	ty_user_info.user_id,
	substring_index( substring_index( ty_user_info.user_scope, ',', mysql.help_topic.help_topic_id + 1 ), ',', - 1 ) userTypeId 
FROM
	ty_user_info
	JOIN mysql.help_topic ON mysql.help_topic.help_topic_id < ( length( ty_user_info.user_scope ) - length( REPLACE ( ty_user_info.user_scope, ',', '' )) + 1 ) 
WHERE
	ty_user_info.user_id = 7958;
posted @ 2022-03-08 14:42  小马快跑3  阅读(126)  评论(0编辑  收藏  举报