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'

即可進行翻譯


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM