On my MYSQL table I have these string :
24015902-C-72
24018504-147
I need extract these output :
24015902 C-72
24018504 147
And I have tried this query :
mysql> SELECT
SUBSTRING_INDEX('24015902-C-72', '-', 1) AS ResultString1,
SUBSTRING_INDEX('24015902-C-72', '-', - 1) AS ResultString2,
SUBSTRING_INDEX('24018504-147', '-', 1) AS ResultString3,
SUBSTRING_INDEX('24018504-147', '-' ,- 1) AS ResultString4;
+---------------+---------------+---------------+---------------+
| ResultString1 | ResultString2 | ResultString3 | ResultString4 |
+---------------+---------------+---------------+---------------+
| 24015902 | 72 | 24018504 | 147 |
+---------------+---------------+---------------+---------------+
1 row in set
mysql>
But on this string 24015902-C-72 the value of C- is lost.
How to do resolve this ?
-2instead of-1. Is there any rule behind this algorithm?