select a.*,
(select GROUP_CONCAT(d.name) from blade_dict d where FIND_IN_SET(d.id, a.repeat)) as 'repeatName2'
from smt_auto a
order by id desc
FIND_IN_SET(str,strlist)函数:
参数str:要查询的字符串
参数strlist:字段名 参数以”,”分隔 如 (1,2,6,8)
查询字段(strlist)中包含(str)的结果,返回结果记录就是预期。
group_concat函数:
连接分组结果
最终效果如下:
灵感来自于http://www.cnblogs.com/wx491592452/p/6404514.html
更多iOS、Android、Python、Java、MySQL的文章,请点击:
http://blog.youkuaiyun.com/jamiecheung
http://blog.youkuaiyun.com/u010841622
本文介绍了一种使用FIND_IN_SET和GROUP_CONCAT函数的方法来实现从一个表中查询并组合多个字段值的需求。通过具体实例展示了如何利用这些SQL函数解决实际问题。
889

被折叠的 条评论
为什么被折叠?



