mysql将一行变成多行的方法:1、将一行变成多行,代码为【substring_index(substring_index( a.rn,’,’,b.help_topic_id + 1 ),’,’ ,- 1)】;2、将多列变成多行。
mysql将一行变成多行的方法:
把
转成
SELECT substring_index(substring_index( a.rn,',',b.help_topic_id + 1 ),',' ,- 1) AS rn FROM (select '1,2,3,4' as rn) a JOIN mysql.help_topic b ON b.help_topic_id <p>图A转成图B</p><p><img src="https://img.php.cn/upload/image/396/912/677/1601262104361576.png" title="1601262104361576.png" alt="19275fe886e86f672f00b79d7057937.png"></p><p>图a</p><p><img src="https://img.php.cn/upload/image/500/405/941/1601262109215136.png" title="1601262109215136.png" alt="6f3e1d38d92ed1e69418732db8a3097.png"></p><p>图b</p><pre class="brush:php;toolbar:false">SELECT substring_index(substring_index( a.rn,',',b.help_topic_id + 1 ), ',' ,- 1 ) AS rn FROM (select SUBSTR(GROUP_CONCAT( REPEAT(CONCAT(number,','),fre) SEPARATOR ''),1,LENGTH(GROUP_CONCAT( REPEAT(CONCAT(number,','),fre) SEPARATOR ''))-1) as rn from numbers ) a JOIN mysql.help_topic b ON b.help_topic_id <blockquote><p><strong>更多相关免费学习推荐:</strong><a href="https://www.php.cn/course/list/51.html" target="_blank"><strong>mysql教程</strong></a><strong>(视频)</strong></p></blockquote>
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END