This article mainly describes the specific operation steps used by the MySQL statistical function GROUP_CONCAT and the code that we will use in the actual operation steps, I hope you will have a better understanding of the actual operations after browsing.
- sql: case when, distinct, group by, group_concat
Optimization of MySQL for large WEB Applications
My base64
Recommendation circle: Database circle
For more information, we recommend that GROUP_CONCAT accumulate the values 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. A simple example
- 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
The 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 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.
The above content describes the usage of the MySQL statistical function GROUP_CONCAT, hoping to help you in this regard.
Edit recommendations]