mysql 使用group_concat()把所有行的id用逗号串连起来

来源:互联网 发布:所罗门矩阵 编辑:程序博客网 时间:2024/06/08 14:23

执行下面语句  

SELECT GROUP_CONCAT(cast(`id` as char(10)) SEPARATOR ',') from table_name

select id,group_concat(name separator ';') from aa group by id;

因为通常id是int类型,直接执行GROUP_CONCAT(id SEPARATOR ','),返回的将是BLOB类型,所以通过cast函数转换字符类型

这样的所有id用逗号串起来的整个字符串

0 0