首页 > 其他 > 详细

GROUP_CONCAT 多行合并

时间:2020-06-27 16:40:45      阅读:60      评论:0      收藏:0      [点我收藏+]

MySQL version:8.0.18-commercial MySQL Enterprise Server - Commercial

语法:
GROUP_CONCAT([DISTINCT] expr [,expr ...]
             [ORDER BY {unsigned_integer | col_name | expr}
                 [ASC | DESC] [,col_name ...]]
             [SEPARATOR str_val])
示例:
mysql> SELECT student_name,
         GROUP_CONCAT(test_score)
       FROM student
       GROUP BY student_name;
Or:

mysql> SELECT student_name,
         GROUP_CONCAT(DISTINCT test_score
                      ORDER BY test_score DESC SEPARATOR ‘ ‘)
       FROM student
       GROUP BY student_name;   

注意:
多行合并的结果会被截断,结果的长度由 group_concat_max_len 控制,默认是1024,最大值可以设置,但是不能超过max_allowed_packet。

SET [GLOBAL | SESSION] group_concat_max_len = val;

官方这句话,是什么意思。。看着不是很懂,应该和结果(result)有关

  The return value is a nonbinary or binary string, depending on whether the arguments are nonbinary or binary strings. 
  The result type is TEXT or BLOB unless group_concat_max_len is less than or equal to 512, in which case the result type is VARCHAR or VARBINARY.

GROUP_CONCAT 多行合并

原文:https://www.cnblogs.com/Coye/p/13198665.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!