mysql处理以逗号隔开的字段内容
有一个字段保存了CheckBox内容,比如职业目标选择对于数据库字段otWorkgoal,保存了1,2,3,4内容
现在需要使用纯mysql语句,将字段otWorkgoal根据内容,进行翻译成中文的内容。
可使用FIND_IN_SET()函数+concat_ws()函数实现。
FIND_IN_SET()可参考https://www.cnblogs.com/zxmceshi/p/5479892.html
concat_ws()可参考http://blog.csdn.net/desilting/article/details/38563087
具体的sql语句如下
select concat_ws(',',(select '为创业积累经验技能与资源' from online_person_info q where find_in_set('1', q.otWorkgoal) and t.id = q.id) ,(select '更高的职位晋升空间' from online_person_info q where find_in_set('2', q.otWorkgoal) and t.id = q.id) ,(select '更好的薪酬待遇' from online_person_info q where find_in_set('3', q.otWorkgoal) and t.id = q.id) ,(select '更具挑战的工作内容 ' from online_person_info q where find_in_set('4', q.otWorkgoal) and t.id = q.id) ,(select '学习到更厉害的专业技能' from online_person_info q where find_in_set('5', q.otWorkgoal) and t.id = q.id) ,(select '更舒适的工作环境' from online_person_info q where find_in_set('6', q.otWorkgoal) and t.id = q.id) ,(select '减小工作压力' from online_person_info q where find_in_set('7', q.otWorkgoal) and t.id = q.id) ,(select '更近的上班距离' from online_person_info q where find_in_set('8', q.otWorkgoal) and t.id = q.id) ,(select '其他' from online_person_info q where find_in_set('9', q.otWorkgoal) and t.id = q.id) ) as otWorkgoal from online_person_info t where t.id='61'
即可进行翻译