Group_concat (expr)
This function merges non-empty column values into grouped conditions and ultimately return. If there is a null value, the return is empty, and its complete syntax is as follows:
Group_concat ([DISTINCT] expr [, expr ...]
[ORDER by { unsigned_integer | col_name | expr}
[ASC | DESC] [, col_name ...]
[SEPARATOR str_val ])
Example Column 1:
SELECT emp_id, sum (VALUE1), sum (VALUE2), sum (VALUE3), Group_concat (Reas_1 SEPARATOR '; '), Group_concat (R eas_2), Group_concat (Reas_3) from Act_gp_testgroup by emp_id
Column 2:
SELECT emp_id, sum (VALUE1), sum (VALUE2), sum (VALUE3), Group_concat (Reas_1,reas_2,reas_3 SEPARATOR '; ') From Act_gp_testgroup by emp_id
The difference between column 1 and column 2 above is that column 2 is the merge of field Reas_1,reas_2,reas_3 as a complete field .
The maximum length of the function receives the environment variablegroup_concat_max_len的限定,其默认值为1024,当然可以设置的更高。同时有效的最大返回长度也受max_allowed_packet的约束。
The syntax to be group_concat_max_len modified in the run is as follows:
SET [GLOBAL | SESSION] Group_concat_max_len = val;
返回的结果是二进制还是非二进制字符,取决于函数内取值字段的本身。一般当group_concat_max_len<=512时,为VARCHAR或VARBINARY,当大于该值时为TEXT和BLOB。
This article is from the "linuxoracle" blog, make sure to keep this source http://onlinekof2001.blog.51cto.com/3106724/1642082
MySQL function group_concat () function