I am trying to get each different value of string between delimiters in MYSQL. I tried using function SUBSTRING_INDEX, it works for the first string and the continuation of that first string, but not the second string. Here is what I meant:
Table x The result
SELECT SUBSTRING_INDEX(path, ':', 2) as p, sum(count) as N From x Group by p UNION
SELECT SUBSTRING_INDEX(path, ':', 3) as p, sum(count) From x Group by p UNION
SELECT SUBSTRING_INDEX(path, ':', 4) as p, sum(count) From x Group by p UNION
SELECT SUBSTRING_INDEX(path, ':', 5) as p, sum(count) From x Group by p UNION
SELECT SUBSTRING_INDEX(path, ':', 6) as p, sum(count) From x Group by p;
I tried adding SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(path, ':', 2), ':', 2) as p, sum(count) From x Group by p UNION
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(path, ':', 4), ':', 2) as p, sum(count) From x Group by p
in the query, but the result is still the same. What I am trying to do is get the result of not only string A1, A2, A3 combination, but also string with B2, C2, D2 as the first string fetched like in table below:
+---------------+----+
| p | N |
+---------------+----+
| :A1 | 4 |
| ... | ...|
| :B1 | 3 |
| :B1:C2 | 2 |
|... | ...|
+---------------+----+
What's the correct function to get the result like that? Any help is appreciated, thank you.