This function returns a string result with the concatenated non-NULL values from a group. It returns NULL if there are no non-NULL values. The full syntax is as follows:

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;

  

In MySQL, you can get the concatenated values of expression combinations. To eliminate duplicate values, use the DISTINCT clause. To sort values in the result, use the ORDER BY clause. To sort in reverse order, add theDESC (descending) keyword to the name of the column you are sorting by in the ORDER BY clause. The default is ascending order; this may be specified explicitly using the ASC keyword. The default separator between values in a group is comma (“,”). To specify a separator explicitly, use SEPARATOR followed by the string literal value that should be inserted between group values. To eliminate the separator altogether, specify SEPARATOR ''.

The result is truncated to the maximum length that is given by the group_concat_max_len system variable, which has a default value of 1024. The value can be set higher, although the effective maximum length of the return value is constrained by the value of max_allowed_packet. The syntax to change the value ofgroup_concat_max_len at runtime is as follows, where val is an unsigned integer:

SET [GLOBAL | SESSION] group_concat_max_len = val;

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. (Prior to MySQL 5.0.19, GROUP_CONCAT() returned TEXT or BLOBgroup_concat_max_len greater than 512 only if the query included an ORDER BY clause.)

quoted from:

https://dev.mysql.com/doc/refman/5.5/en/group-by-functions.html#function_group-concat

GROUP_CONCAT(expr)的更多相关文章

  1. mysql行转列,函数GROUP_CONCAT(expr)

    demo: 语句: SELECT '行' id, '' product_nameUNIONSELECT id, product_name FROM `product` WHERE id < 5 ...

  2. 【MySQL】MySQL的group_concat使用例子

    > 参考的优秀文章 GROUP_CONCAT(expr) > 简单的例子 此函数的功能,是拼接group分组多行的数据为一行,并可以指定去重.排序.分隔符. 例子: select t.na ...

  3. MySQL拼接字符串,GROUP_CONCAT 值得拥有

    上一篇文章 跨表更新,看到自己写的SQL像个憨憨写了关于跨表个更新的内容.一年过的很快,文中后来的两位员工 馮大 和 馮二 也要面对无情的 KPI 考核了,他们工作干的很不错,performance ...

  4. 分组拼接字符串,GROUP_CONCAT

    背景 一年过的很快,文中后来的两位员工 馮大 和 馮二 也要面对无情的 KPI 考核了,他们工作干的很不错,performance 分别是 4 和 5 新需求来了,静悄悄的来了!!! 领导想要查看每个 ...

  5. MySQL、DM 行转列及字段去重(Group_Concat())

    最近在使用数据库迁移适配,由MySQL 库迁移到达梦数据库,其中进行行转列时,MySQL转换达梦sql语法有些问题,特记录. 在MySQL 下有Group_Concat(expr)  ,在达梦及神通数 ...

  6. 我的MYSQL学习心得(六) 函数

    我的MYSQL学习心得(六) 函数 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据类 ...

  7. mysql函数大全

    对于针对字符串位置的操作,第一个位置被标记为1. ASCII(str) 返回字符串str的最左面字符的ASCII代码值.如果str是空字符串,返回0.如果str是NULL,返回NULL. mysql& ...

  8. MySQL 函数大全

    mysql函数大全 对于针对字符串位置的操作,第一个位置被标记为1. ASCII(str) 返回字符串str的最左面字符的ASCII代码值.如果str是空字符串,返回0.如果str是NULL,返回NU ...

  9. mysql常用函数参考

    mysql常用函数参考   对于针对字符串位置的操作,第一个位置被标记为1. ASCII(str) 返回字符串str的最左面字符的ASCII代码值.如果str是空字符串,返回0.如果str是NULL, ...

随机推荐

  1. Python正则表达式-基础

    Python正则表达式-基础 本文转载自昔日暖阳,原文地址:http://www.osheep.cn/4806.html python使用正则,需要先引入re模块 import re 匹配符 单个字符 ...

  2. python三大神器之迭代器

    可迭代协议: 内部含有__iter__方法的值/变量都是可迭代的.可迭代类型和python语言之间的协议. 可迭代对象: iterable,内部包含__iter__()函数. 迭代器: iterato ...

  3. 内存泄漏导致程序killed

    示例程序: #include<stdio.h> #include<unistd.h> int main() { ) { *]; } ; } 执行结果: 程序消耗完内存会被kil ...

  4. 003---random随机数模块

    import random # 随机数(0-1) print(random.random()) # 随机整数, 包含尾巴 print(random.randint(-1, 2)) # 不包含尾巴 pr ...

  5. Hyperledger Fabric国密改造

    Fabric国密改造是个什么概念?我们来思考以下4个问题: 为什么偏偏是密码算法?(WHY?) 什么是国密算法?(WHAT?) 改造切入点什么?(WHERE?) 如何实现国密支持?(HOW?) 1.为 ...

  6. [Cracking the Coding Interview] 4.3 List of Depths

    Given a binary tree, design an algorithm which creates a linked list of all the nodes at each depth. ...

  7. git之解决冲突

    前面几次使用git,一直对于冲突的这个问题不是很理解,感觉有些时候就会产生冲突,在此记录一下解决冲突的流程 1.git bash上面冲突显示 2.在idea上面可以看到冲突的文件 3.去解决冲突 4. ...

  8. Xshell 清除历史记录方法

    使用电脑久了,就会清理电脑,将一些历史记录清除,使得电脑可以运行的更快,Xshell也是同样的道理.本集小编就教大家如何清除xshell的历史记录. 如何清除历史记录: 1.打开xshell,然后点击 ...

  9. MySQL源码中的String

    适用于离开作用域就销毁的字符串.

  10. error LNK2001: unresolved external symbol "public: __thiscall ControllerInterface::ControllerInterface(class QObject *)" (??0ControllerInterface@@QAE@PAVQObject@@@Z) downloadcontroller.obj

    前几天刚遇到这个问题,但是今天再碰到就又要思考怎么解决.这次特别记录一下,以防下次碰到再手足无措: 1.看到这个报错第一感觉LNK关键字,表示连接错误,这种错误有几个可以下手的点 1)函数声明和定义是 ...