A very useful function group_concat(), the manual states: This function returns a string result with non-NULL values from a group connection. To put it simply, group_concat() will calculate which rows belong to the same group and merge the columns that belong to the same group and display them together. Which columns to return is determined by the function parameters (that is, the field names). There must be a standard for grouping, that is, grouping according to the column specified by group by. The default separator for merged fields is a comma, which can be specified using the separator parameter. For example, in the student table, there are 5 pieces of data as follows: The requirements are as follows: "Xiao Ming"'s two rows of scores can be displayed on one row, and "Xiao Hong"'s two rows of scores can also be displayed on one row! Then you can use SELECT name,group_concat(subject,score) FROM student group by name; The query results are as follows: You can also customize the delimiter SELECT name,group_concat(subject,score separator '--') FROM student group by name; The query results are as follows: What happens if you don't use group by name;? SELECT name,group_concat(subject,score) FROM student; The query results are as follows (only one row is shown, which has nothing to do with the name attribute): The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: How to define data examples in Vue
>>: Web project development JS function anti-shake and throttling sample code
Table of contents 1. Check the status of the serv...
Install MySQL and keep a note. I don’t know if it...
1. --cpu=<value> 1) Specify how much availa...
1. W3C versions of flex 2009 version Flag: displa...
Html event list General Events: onClick HTML: Mous...
transform: scale(); Scaling will cause jitter in ...
Preface Recently, I have been taking some time in...
Table of contents Previous words Synchronous and ...
Here, clever use of CSS techniques allows you to g...
Table of contents Multi-table join query Inner Jo...
After a lot of trouble, I finally figured out the...
1. Prepare the environment (download nodejs and s...
I updated MySQL 8.0 today. The first problem: Nav...
Today I had a sneak peek at IE8 beta 1 (hereafter...
This article originated from my complaints about ...