Use the group_concat() function in MySQL for grouping and sorting

The parameters of the group_concat() function can be directly sorted by order by. The following is an example to illustrate, first look at the t1 table below.

For example, we want to check the multiple scores of each person, display the multiple scores corresponding to the person together, and sort the scores from high to bottom. Can be written like this:

SELECT username,GROUP_CONCAT(score ORDER BY score DESC) AS myScore FROM t1 GROUP BY username;

The effect is as follows:

If reprinted, please indicate the source: Open Source Byte   https://sourcebyte.vip/article/315.html

 

Guess you like

Origin blog.csdn.net/qq_35634154/article/details/130666356