How to get substring from column which contains records for filter and group by clause in AWS Redshift database.
I have table with records like:
Table_Id
To do this fully dynamically, you need to transpose or pivot values in "categories" column into separate rows. Unfortunately, a "fully dynamic" solution (without knowing the different values beforehand) is NOT possible using redshift.
Your options are as follows:
Use the method suggested by AlexYes in another answer. This is semi-dynamic and is probably your best option.
Outside of Redshift, run some ETL code to perform the column -> multiple rows ETL.
Create a hardcoded type solution, and perform the pivot something like this:
select table_id,'ABC1' as category, case when concat(Categories,';') ilike '%ABC1;%' then value else 0 end as value from your_table union all select table_id,'ABC1-1' as category, case when concat(Categories,';')ilike '%ABC1-1;%' then value else 0 end as value from your_table union all
etc