I have a view that aggregates data about customers and shows the products they have access to, along with the status of whether they use those products on a trial basis or not (both as string comma seperated values):
+----------+----------+-----------------------+
| customer | products | products_trial_status |
+----------+----------+-----------------------+
| 234253 | A,B,C | false,true,false |
| 923403 | A,C | true,true |
| 123483 | B | true |
| 239874 | B,C | false,false |
+----------+----------+-----------------------+
and I would like to write a query that returns a list of customers who are using a certain product on a trial.
e.g. I want to see which customers using product B are on a trial, I would get something like this:
+----------+
| customer |
+----------+
| 234253 |
| 123483 |
+----------+
The only way I can think of doing this is by checking the products
column for the position of the product in the string (if it exists there), then checking the corresponding value at the same position in the products_trial_status
column and whether it is equal to true.
i.e. for customer 234253, product B is in position 2 (after the first comma), so it's corresponding trial status in the column would also be in position 2 after the first comma there.
How would I go about doing this?
I am aware that storing such data as a string of values is not good practice but it is not something i can change, so would need to work out using the format it is in