I have a single column in my table (table name is rtp2k) that contains multiple values separated by a comma. I would like to split these values and then list them by number.
My column currently looks like:
+-------+
| A2 |
| a,b,c |
| d,e,f |
| c,b |
| a,d,f |
| d,e,f |
+-------+
I know this is not best practice. I did not create this table. I am just supposed to pull data from it to make a chart using mysqli, php and google charts by a deadline.
My current query looks like this, but I don't need the id in there and I would like to count them by value instead of listing each individually.
select
rtp2k.id,
SUBSTRING_INDEX(SUBSTRING_INDEX(rtp2k.a2, ',', numbers.n), ',', -1) a2
from
(select 1 n union all
select 2 union all select 3 union all
select 4 union all select 5) numbers INNER JOIN rtp2k
on CHAR_LENGTH(rtp2k.a2)
-CHAR_LENGTH(REPLACE(rtp2k.a2, ',', ''))>=numbers.n-1
order by
id, n
I would like the query to return something like:
a - 2
b - 2
c - 2
d - 3
e - 2
f - 3
basically separating the string by value and listing how many of each there is.
My current result is: this table
I would be very grateful for any assistance.