I have a column which has a list of products in each row. e.g:
- bat,ball,gloves
- bat,gloves
- shoes,gloves
I want to make a new column for each of the product, which will have a value of 1 or 0 depending on if that product exists in that row.
I'm using the following code right now:
select
*,
CASE WHEN product_name LIKE '%bat%' THEN 1 else 0 END AS bat,
CASE WHEN product_name LIKE '%gloves%' THEN 1 else 0 END AS gloves
from products
It does not work. Kindly help