字段内容为类似“1,5,9”格式的主键拼接字符串,需要把主键对应的名称查询出来并拼接为相应的字符串:
·····表a:—————————— ······表b:
id·······name—————————id·······code
1·······张三——————————1·······1,2
2·······李斯——————————2·······2
3·······王屋——————————3·······1,2,3
(select GROUP_CONCAT(a.name) from table_a a where FIND_IN_SET(a.id,b.code)) as b.code
返回数据即为:张三,李斯/李斯/张三,李斯,王屋
如果想加单引号:
GROUP_CONCAT("'",a.name,"'")
返回数据即为:‘张三’,‘李斯’/‘李斯’/‘张三’,‘李斯’,‘王屋’
网友评论