MySQL function group_concat () function

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.