1. 程式人生 > 其它 >mysql 切割字串,實現split 一行變多行

mysql 切割字串,實現split 一行變多行

技術標籤:sqlmysqlsql資料庫

簡單點,表結構;

實現效果:

sql:

SELECT a.id,
 SUBSTRING_INDEX(
  SUBSTRING_INDEX(
     a.citys,
   ',',
   help_topic_id + 1
  ),
  ',' ,- 1
 ) AS city
FROM
 mysql.help_topic,
 a_test AS a
WHERE
 help_topic_id < LENGTH(a.citys) - LENGTH(
  REPLACE (
   a.citys,
   ',',
   ''
  )
 ) + 1
AND a.id = '1'

說明:help_topic是資料庫自帶表