Home > Database > Mysql Tutorial > MySQL statistical function GROUP_CONCAT uses trap analysis_MySQL

MySQL statistical function GROUP_CONCAT uses trap analysis_MySQL

WBOY
Release: 2016-07-06 13:32:47
Original
1275 people have browsed it

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;


You can also sort and set separators, which is powerful.

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.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template