Introduction to MySQL statistical function GROUP_CONCAT

Source: Internet
Author: User

The following articles mainly describe the actual usage of the MySQL statistical function GROUP_CONCAT, if you are interested in the actual usage of the MySQL statistical function GROUP_CONCAT, you can click the following article to view it.

GROUP_CONCAT accumulates the value of a field based on the specified characters. The default Delimiter is comma, and the length of characters that can be accumulated is 1024 bytes. You can modify these parameters.

1. MySQL statistical function GROUP_CONCAT: A simple example is given first.

 
 
  1. select group_concat(f_a) from t_one group by f_b; 

Query by group by f_ B and accumulate f_a in each group.

2. Modify the default delimiter

 
 
  1. select group_concat(f_a separator '_') from t_one group by f_b; 

Separator is a keyword followed by the characters to be separated

3. Sorting

 
 
  1. select group_concat(f_a order by f_a separator '_') from t_one group by f_b; 

4. Modify the default character size

1) Add the following in the MySQL configuration file:

Group_concat_max_len = 102400 # maximum length you want

2). You can simply execute the statement and set the scope of the action.

 
 
  1. SET GLOBAL group_concat_max_len=102400;  
  2. SET SESSION group_concat_max_len=102400; 

5. Use of the MySQL statistical function GROUP_CONCAT: used with concat

Group_concat by default, a large BLOB Object is returned. You can use concat to return a string. You can also add other data in the returned content.


The above content is an introduction to the usage of the MySQL statistical function GROUP_CONCAT. I hope you will have some gains.

Related Article

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.