I have a table that stores Labels (aka "tags") in one column, comma separated for each row.
Here is an example:
Id, Labels, .... <- These are the column headers
---------------------------------------------------------------------------
"123", "usability, subscriptions", ...
"325", "usability, membership, reports", ...
I would like to report on the Labels column but it's impossible to build a pie chart breaking down the Labels usage in the current format, so I went searching online for some solutions. I found two SQL examples that explain how to split a single record into multiple records:
I'm basically trying to transform may data in a Query Table to be something like so:
Id, Label, .....
---------------------------------------------------------------------------
"123", "usability", ....
"123", "subscriptions", ...
"325", "usability", ...
"325", "
membership", ...
"325", "
reports", ...
Does this make sense?
Both of the examples I found (linked above) use a "Numbers" table to help in parsing the comma-separated list values. I created by own "Numbers" table and a "Number" column and values from 1 - 1000.
Here is the query I've got right now:
- SELECT "Id",
- substring( "Labels", "Number",
- substring_index( ',', "Labels" + ',', "Number" ) - "Number" ) as "Label"
- FROM "Stories"
- INNER JOIN "Numbers"
- ON substring( ',' + "Labels", "Number", 1 ) = ','
The query will actually run, but I don't get any results back. Is this something that's even possible or am I close?
Thanks for any help!