Mysql 中将数组连接成字符串返回
1.有时候查出来是这种结果,有多条记录,但是我们想要合并成一条记录让他成为一个字段,应该怎么做呢?
预期效果
2.很简单,sql给我们提供了函数 GROUP_CONCAT
原语句
SELECT tc.title as title from t_category tc where tc.id in (select category_id from t_goods where t_goods.user_id=99234564391568383 GROUP BY category_id)
更改之后
SELECT GROUP_CONCAT(tc.title SEPARATOR ',') as title from t_category tc where tc.id in (select category_id from t_goods where t_goods.user_id=99234564391568383 GROUP BY category_id)
3.最终放到别的查询中,实现想要的效果
版权属于:virgo's blog(除特别注明外)
本文链接:https://blog.scqloud.cn/archives/18.html
转载时须注明出处及本声明