GROUP_CANCAT()函数
手册上说明:该函数返回带有来自一个组的连接的非NULL值的字符串结果。
字面意思比较难理解,从以下测试SQL可以很清楚的表达出意思。
- create table a2 (id int(3),mz varchar(10));
- insert into a2 values ('1','www'),('1','eee'),('2','qqq'),('3','ttt'),('2','gg');
- select id,group_concat(mz) as mz from a2 group by id;
- +------+---------+
- | id | mz |
- +------+---------+
- | 1 | www,eee |
- | 2 | qqq,gg |
- | 3 | ttt |
- +------+---------+
对mz排序并使用"分隔
- select id,group_concat(mz order by mz asc separator '"') as mz from a2 group by id;
- +------+---------+
- | id | mz |
- +------+---------+
- | 1 | eee"www |
- | 2 | gg"qqq |
- | 3 | ttt |
- +------+---------+
阅读(3192) | 评论(0) | 转发(0) |