MySQL group_concat
2015-07-21 23:40
555 查看
group_concat()会计算哪些行属于同一组,将属于同一组的列显示出来,实现字段的列转行设置
语法:
以默认的逗号作为分隔符
order
separator
注意:默认下,group_concat()长度为1024,
group_concat截取的结果 会发现 缺失,
修改参数方法:
set global group_concat_max_len = 102400;
或者修改 my.ini 中group_concat_max_len
语法:
GROUP_CONCAT([DISTINCT] expr [,expr ...] [ORDER BY {unsigned_integer | col_name | expr} [ASC | DESC] [,col_name ...]] [SEPARATOR str_val])
mysql> select * from t_test; +------+ | id | +------+ | 1 | | 2 | | 3 | | 4 | | 5 | +------+ 5 rows in set (0.00 sec)
以默认的逗号作为分隔符
mysql> select group_concat(id) from t_test; +------------------+ | group_concat(id) | +------------------+ | 1,2,3,4,5 | +------------------+ 1 row in set (0.00 sec)
order
mysql> select id,group_concat(name order by name desc) from t_test group by id;
separator
SELECT id,group_concat(name,separator ';') groups FROM t_test group by id; +----+------------+ | id | groups | +-------+---------+ | 1 | tom;Jim | | 2 | hulu | | 3 | Jack;opt | | 4 | | | 5 | Sam;phony;childish | +---+---------------------+
注意:默认下,group_concat()长度为1024,
group_concat截取的结果 会发现 缺失,
修改参数方法:
set global group_concat_max_len = 102400;
或者修改 my.ini 中group_concat_max_len
相关文章推荐
- Mycat(4):消息表mysql数据库分表实践
- 3.4 实例 playbook安装mysql
- mysql部分学习心得(入门级别)
- Mysql 数据备份与恢复,用户创建,授权
- Mysql 环境配置查询
- MySQL进阶---MySql常用命令总结
- 理解MySQL――索引与优化
- 5.3以上建议使用mysqlnd驱动
- MySQL执行存储过程权限
- MySQL计数器表的设计
- JDBC连接MySql数据库
- mysql group by/having/distinct 查询使用例子
- MySQL 用户权限详细汇总
- MySQL中删除所有表的方法
- Mac安装MySQLdb
- 服务器保持与Mysql的连接
- mysql乱码的好文
- Ubuntu下mysql设置远程访问
- Node.js Express连接mysql完整的登陆注册系统(windows)
- Ubuntu14安装mysql命令