I have a table of data like:
ID1 F1. F2. F3
X1. Enabled. Disabled. Disabled
X2. Disabled. Enabled. Enabled.
I'd like to get it into the form of:
ID1 Fields
X1. F1
X2. F2,F3
But I'm having writers block on how to approach the problem. Is this something a pivot would help with? Self-joining the table? I've tried some group_concat() aggregations on if() statements to no avail, similarly with grouping on case whens.
CodePudding user response:
SELECT ID1, CONCAT_WS(',', NULLIF(F1,'Disabled'), NULLIF(F2,'Disabled'), NULLIF(F3,'Disabled')) AS Fields
FROM ...
See: