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
Preface When backing up the database, a full data...
Overview The fundamental difference between async...
Summary HTML: element plus v-cloak CSS: [v-cloak]...
1 Get the installation resource package mysql-8.0...
1. Press win + R and type cmd to enter the DOS wi...
Meta tag function The META tag is a key tag in th...
Encapsulate el-dialog as a component When we use ...
MySQL Users and Privileges In MySQL, there is a d...
I have several tomcats here. If I use them at the...
Introduction After compiling, installing and solv...
This article shares the specific implementation c...
Table of contents background Solution 1 Ideas: Co...
This article shares the specific code of react+an...
Table of contents K8S Master Basic Architecture P...
Sometimes it is slow to download large network fi...