This article analyzes the pitfalls in the use of MySQL statistical function GROUP_CONCAT with examples. Share it with everyone for your reference, the details are as follows:
Recently I am using MySQL to do some data preprocessing, and I often use the group_concat function, such as a statement similar to the following
The code is as follows:
mysql>select aid,group_concat(bid) from tbl group by aid limit 1;
The SQL statement is relatively simple, grouped according to aid, and string the corresponding bids with commas. You may have used this sentence before, and it may not cause problems, but if there are a lot of bids, you should be careful, such as the following prompt message:
The code is as follows:
mysql>select aid,group_concat(bid order by bid separator ',') as bid_str from tbl group by aid;
Readers who are interested in more MySQL-related content can check out the special topics on this site: "A Complete Collection of MySQL Log Operation Skills", "A Summary of MySQL Transaction Operation Skills", "A Complete Collection of MySQL Stored Procedure Skills", and "A Summary of MySQL Database Lock Related Skills" 》and《Summary of commonly used functions in MySQL》
I hope this article will be helpful to everyone in MySQL database planning.