MySQL - 如何在分隔符之间提取所有值

时间:2015-08-24 10:48:29

标签: mysql

我有一个由调度程序应用程序创建的表,该表包含ID形式的WEEK["1","2","5","10","20","52"]两列。
我想提取和标准化ID和WEEK列,以便能够绘制时间轴。不幸的是,我甚至不知道从哪里开始。

1 个答案:

答案 0 :(得分:0)

SELECT * FROM ints;
+---+
| i |
+---+
| 0 |
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
| 7 |
| 8 |
| 9 |
+---+


SELECT DISTINCT SUBSTRING_INDEX (SUBSTRING_INDEX('1,2,5,10,20,52',',',i+1),',',-1)+0 x FROM ints;
+----+
| x  |
+----+
|  1 |
|  2 |
|  5 |
| 10 |
| 20 |
| 52 |
+----+