In the following article, the Han nationality wants to talk about the specific use scheme of MySQLGROUP_CONCAT. In order to describe the specific operation steps of MySQLGROUP_CONCAT in more detail, we also give an example to better explain it, the following describes the specific solution.
- 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 # 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 the description of MySQLGROUP_CONCAT, and I hope it will help you in this regard.