group_concat有长度限制
group_concat有长度限制 group_concat 详细用法请点此链接.
长度陷阱
用了group_concat后,select里如果使用了limit是不起作用的.
用group_concat连接字段的时候是有长度限制的,并不是有多少连多少。但你可以设置一下。
使用group_concat_max_len系统变量,你可以设置允许的最大长度。
程序中进行这项操作的语法如下,其中 val 是一个无符号整数:
SET [SESSION | GLOBAL] group_concat_max_len = val;
若已经设置了最大长度,则结果被截至这个最大长度。
在SQLyog中执行 SET GLOBAL group_concat_max_len = 10 后,重新打开SQLyog,设置就会生效。
---------------------------
GROUP_CONCAT将某一字段的值按指定的字符进行累加,系统默认的分隔符是逗号,可以累加的字符长度为1024字节。可以对这些参数进行修改。
1.先举一个简单的例子
select group_concat(f_a) from t_one group by f_b;
按f_b进行分组查询,将每组中的f_a进行累加。
2.修改默认的分隔符
select group_concat(f_a separator '_') from t_one group by f_b;
separator 是一个关键字,后面跟着要进行分隔的字符
3.排序
select group_concat(f_a order by f_a separator '_') from t_one group by f_b;
4.修改默认字符大小
1).在MySQL配置文件中加上
group_concat_max_len = 102400 #你要的最大长度
2).可以简单一点,执行语句,可以设置作用范围
SET GLOBAL group_concat_max_len=102400;后直接跟包含group_concat 的sql语句即可。
SET SESSION group_concat_max_len=102400;后直接跟包含group_concat 的sql语句即可。
5.和concat使用
group_concat默认返回的是BLOB大对象,可以使用concat,返回字符串,还可以在返回的内容,在加入其它的数 据。
一.测试数据准备
mysql> use test;
Database changed
mysql> select * from t_kenyon;
+------+
| id |
+------+
| 1 |
| 123 |
| 789 |
| 345 |
| 78 |
+------+
5 rows in set (0.00 sec)
二.使用经过
1.以默认的逗号作为分隔符
mysql> select group_concat(id) from t_kenyon;
+------------------+
| group_concat(id) |
+------------------+
| 1,123,789,345,78 |
+------------------+
1 row in set (0.00 sec)
2.对ID值进行排序后行转列
mysql> select group_concat(id order by id) from t_kenyon;
+------------------------------+
| group_concat(id order by id) |
+------------------------------+
| 1,78,123,345,789 |
+------------------------------+
1 row in set (0.00 sec)
3.使用其他分割符,如*和;等
mysql> select group_concat(id separator '*') from t_kenyon;
+--------------------------------+
| group_concat(id separator '*') |
+--------------------------------+
| 1*123*789*345*78 |
+--------------------------------+
1 row in set (0.00 sec)
4.分隔符与排序结合起来用
mysql> select group_concat(id order by id separator '_') from t_kenyon;
+--------------------------------------------+
| group_concat(id order by id separator '_') |
+--------------------------------------------+
| 1_78_123_345_789 |
+--------------------------------------------+
1 row in set (0.00 sec)
5.对相同的值分组
mysql> insert into t_kenyon values (78);
Query OK, 1 row affected (0.00 sec) mysql> select group_concat(id) from t_kenyon group by id;
+------------------+
| group_concat(id) |
+------------------+
| 1 |
| 78,78 |
| 123 |
| 345 |
| 789 |
+------------------+
5 rows in set (0.00 sec)
三.参数设置与限制说明
1.查看服务器中设置
mysql> show variables like '%group_concat%';
+----------------------+-------+
| Variable_name | Value |
+----------------------+-------+
| group_concat_max_len | 1024 |
+----------------------+-------+
1 row in set (0.00 sec)
以上设置的值说明当前是默认长度1KB
2.改变参数值
方法一:修改配置文件中参数,新增 group_concat_max_len = 10240
方法二:在会话中实现,全局或当前session中
SET GLOBAL group_concat_max_len=10240;
SET SESSION group_concat_max_len=10240;
group_concat有长度限制的更多相关文章
- mysql group_concat的长度问题
mysql group_concat的长度问题 show variables like 'group_concat_max_len';+----------------------+-------+| ...
- MYSQL中group_concat有长度限制!默认1024
在mysql中,有个函数叫"group_concat",平常使用可能发现不了问题,在处理大数据的时候,会发现内容被截取了,其实MYSQL内部对这个是有设置的,默认不设置的长度是10 ...
- MYSQL中group_concat有长度限制!默认1024(转载)
在mysql中,有个函数叫“group_concat”,平常使用可能发现不了问题,在处理大数据的时候,会发现内容被截取了,其实MYSQL内部对这个是有设置的,默认不设置的长度是1024,如果我们需要更 ...
- mysql深坑之--group_concat有长度限制!!!!默认1024
在mysql中,有个函数叫“group_concat”,平常使用可能发现不了问题,在处理大数据的时候,会发现内容被截取了,其实MYSQL内部对这个是有设置的,默认不设置的长度是1024,如果我们需要更 ...
- group_concat默认长度限制
这几天做后台一个订单汇总数据报表时,发现当使用group_concat函数时,发现会漏掉数据,究其原因是因为这个函数有默认长度显示1024 可以修改mysql配置文件my.ini 设置group_co ...
- 【BUG之group_concat默认长度限制】
2019独角兽企业重金招聘Python工程师标准>>> 问题:mysql数据库使用group_concat将多个id组成字符串数组,一共200个,到160个被截断: 原因:mysql ...
- mysql group_concat函数是有长度限制的
在表关联查询中,特别是一对多关系的表查询中,group_concat函数是很有用的一个函数,帮助我们减少对数据库查询的次数,减少服务器的压力. 但是今天使用group_concat函数查询数据库时,发 ...
- mysql group_concat时间用法
第一张表的worksId在第二张表中对应多条数据,需要将每条数据的日期作为结果查询出来,一个作为“初审时间”,另一个作为“复审时间”: 可以使用group_concat 和 group by 来进行分 ...
- 浅析MySQL中concat以及group_concat的使用
说明: 本文中使用的例子均在下面的数据库表tt2下执行: 一.concat()函数 1.功能:将多个字符串连接成一个字符串. 2.语法:concat(str1, str2,...) 返回结果为连接 ...
随机推荐
- Linux常用命令 - wget命令详解(重点)
21篇测试必备的Linux常用命令,每天敲一篇,每次敲三遍,每月一循环,全都可记住!! https://www.cnblogs.com/poloyy/category/1672457.html 下载i ...
- Spring Cloud 系列之 Netflix Hystrix 服务监控
Actuator Hystrix 除了可以实现服务容错之外,还提供了近乎实时的监控功能,将服务执行结果和运行指标,请求数量成功数量等等这些状态通过 Actuator 进行收集,然后访问 /actuat ...
- FormData/Go分片/分块文件上传
FormData 接口提供了一种表示表单数据的键值对的构造方式,经过它的数据可以使用 XMLHttpRequest.send() 方法送出,本接口和此方法都相当简单直接.如果送出时的编码类型被设为 & ...
- 表格的删除与添加以及id的唯一性
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...
- 【NLP面试QA】预训练模型
目录 自回归语言模型与自编码语言 Bert Bert 中的预训练任务 Masked Language Model Next Sentence Prediction Bert 的 Embedding B ...
- [Flink] Flink的waterMark的通俗理解
导读 Flink 为实时计算提供了三种时间,即事件时间(event time).摄入时间(ingestion time)和处理时间(processing time). 遇到的问题: 假设在一个5秒的T ...
- 移动深度学习 Mobile-deep-learning(MDL)
Free and open source mobile deep learning framework, deploying by Baidu. This research aims at simpl ...
- Swagger2 初始用
1.结合Spring-Boot 引入 pom 依赖 <dependency> <groupId>io.springfox</groupId> <artifa ...
- IOS 空字符串报错 解决办法
NSScanner: nil string argument NSScanner: nil string argument libc++abi.dylib: terminate_handler un ...
- [noip2012]国王游戏<贪心+高精度>
题目链接: https://vijos.org/p/1779 https://www.luogu.org/problem/show?pid=1080 http://codevs.cn/problem/ ...