I have a table created by a scheduler application that contains two columns, ID
and WEEK
in the form of ["1","2","5","10","20","52"]
.
I would like to extract and normalize the ID and WEEK columns to be able to plot a timeline. Unfortunately I wouldn't even know where to start.
Asked
Active
Viewed 74 times
0

Zakaria
- 14,892
- 22
- 84
- 125

user3112246
- 121
- 1
- 5
-
possible duplicate of [MySQL Split Comma Separated String Into Temp Table](http://stackoverflow.com/questions/11835155/mysql-split-comma-separated-string-into-temp-table) – Christian Kiewiet Aug 24 '15 at 10:49
1 Answers
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 |
+----+

Strawberry
- 33,750
- 13
- 40
- 57
-
I do have more than one row. In fact I need to create temp tables out of any given row in that schedule table to be used in some views elsewhere. I do at temp table creation only know the scheduler id and not what is in the weeks column. As a complication I'd have to process any request in ONE select statement, not 1+n – user3112246 Aug 28 '15 at 20:27