MySQL之GROUP_CONCAT()
分类:SQL
MySQL的group_concat()函数可太好用了
将作用是将属于同一组的列显示出来,所以和group by一同使用,同一组的默认以逗号分隔显示
基础语法:select group_concat(列 SEPARATOR ',') from tablename group by 列名
SEPARATOR 定义以什么分隔结果,可以不写,不写就是默认以逗号分隔;
案例1:
案例2:
注意:
group_concat的结果字符串有长度限制;
#查看最大长度限制
select @@session.group_concat_max_len,@@session.group_concat_max_len;
#设置长度限制值
set GLOBAL group_concat_max_len = 16383;
set session group_concat_max_len = 16383;