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.
- 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
- 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
- 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.
- SET GLOBAL group_concat_max_len=102400;
- 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.