I have a table with an existing
user_agent column that I want to make a new column based on if user agent contains the substrings
'os x' in MySQL and I can’t figure out what is wrong or find examples of case statements with
LIKE for strings on this site. My version of
SELECT user_id, CASE user_agent WHEN LIKE '%windows%' THEN 'Windows' WHEN LIKE '%OS X%' THEN 'Mac' Else 'Other' END AS Operating System FROM pageviews;
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
SELECT user_id, CASE WHEN user_agent LIKE '%windows%' THEN 'Windows' WHEN user_agent LIKE '%OS X%' THEN 'Mac' Else 'Other' END AS `Operating System` FROM pageviews;