Even for data transformation logic, SQL isn’t the best choice. How would you handle the case when you need to apply the same transformations to few dozens or hundreds columns?
[1] https://mariadb.com/kb/en/quote/
You can then specify columns as a query, group_concat the result and evaluate resulting statement [2].
https://mariadb.com/kb/en/execute-immediate/
I hope that helps.