Last active
November 8, 2019 03:58
-
-
Save melotusme/4c05c0a43489563ec23d9472464c5bbd to your computer and use it in GitHub Desktop.
sql mysql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- mysql 行转列, 一个字段转成多行记录 | |
-- 使用了辅助表 mysql.help_topic | |
SELECT | |
id, b.help_topic_id, SUBSTRING_INDEX( SUBSTRING_INDEX(id,',', b.help_topic_id+1),',',-1) | |
FROM | |
( SELECT "1,2,3,4,5" AS id ) a | |
JOIN mysql.help_topic b ON b.help_topic_id < ( LENGTH( a.id ) - LENGTH( REPLACE ( a.id, ',', '' ))+ 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment