GROUP_CONCAT(expr)
2014-03-02 14:04
239 查看
This function returns a string result with the concatenated non-
[ORDER BY {
[ASC | DESC] [,
[SEPARATOR
[/code]
Or:
In MySQL, you can get the concatenated values of expression combinations. To eliminate duplicate values, use the
The result is truncated to the maximum length that is given by the
[/code]
The return value is a nonbinary or binary string, depending on whether the arguments are nonbinary or binary strings. The result type is
quoted from:
https://dev.mysql.com/doc/refman/5.5/en/group-by-functions.html#function_group-concat
NULLvalues from a group. It returns
NULLif there are no non-
NULLvalues. The full syntax is as follows:
GROUP_CONCAT([DISTINCT] [code]expr[,
expr...]
[ORDER BY {
unsigned_integer|
col_name|
expr}
[ASC | DESC] [,
col_name...]]
[SEPARATOR
str_val])
[/code]
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
DISTINCTclause. To sort values in the result, use the
ORDER BYclause. To sort in reverse order, add the
DESC(descending) keyword to the name of the column you are sorting by in the
ORDER BYclause. The default is ascending order; this may be specified explicitly using the
ASCkeyword. The default separator between values in a group is comma (“
,”). To specify a separator explicitly, use
SEPARATORfollowed 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_lensystem 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 of
group_concat_max_lenat runtime is as follows, where
valis an unsigned integer:
SET [GLOBAL | SESSION] group_concat_max_len = [code]val;
[/code]
The return value is a nonbinary or binary string, depending on whether the arguments are nonbinary or binary strings. The result type is
TEXTor
BLOBunless
group_concat_max_lenis less than or equal to 512, in which case the result type is
VARCHARor
VARBINARY. (Prior to MySQL 5.0.19,
GROUP_CONCAT()returned
TEXTor
BLOB
group_concat_max_lengreater than 512 only if the query included an
ORDER BYclause.)
quoted from:
https://dev.mysql.com/doc/refman/5.5/en/group-by-functions.html#function_group-concat
相关文章推荐
- windows操作系统版本历史
- 斗地主算法(4)
- memcache与一致性HASH算法
- UML之构件图和部署图
- C#中有趣的预处理指令
- <读书笔记> windows内核安全 --- 串口过滤(1)
- hdu3038
- ASP.net验证控件详解和按钮点击事件后验证控件的执行顺序问题以及在确认密码框为空,CompareValidator认为是合法的问题的解决方案
- 分析一个文档(英语文章)中各个词出现的频率,并打印频率最高的前10个。
- 2013蓝桥杯【初赛试题】高斯日记
- maven项目出现红色感叹号
- 用枚举表示对称方式
- BOIS中功能小知识
- 由Josephus问题说开去(to be continued)
- Linux内核设计的艺术-前三章总结
- python socket简单使用
- 简单工厂、工厂方法模式和抽象工厂模式的分析
- 算法学习--排序
- 对于5位任意数,求其降序数
- 解决AJAX中使用UpdatePanel后再用RegisterStartupScript等无法弹出对话框问题