Group_concat () calculates which rows belong to the same group and displays the columns that belong to the same group. Which columns to return, by letter
The number parameter (that is, the field name) is determined. Groupings must have a standard, grouped by the columns specified by group BY.
The Group_concat function should have executed the group by statement internally, which is my guess.
1. Test statement:
The code is as follows |
Copy Code |
SELECT Group_concat (town) from ' players ' group by town |
The result is to look up town to find out which values are the same, and if they are equal, list them all, listed as comma-separated, as follows:
Group_concat (town)
BEIJING, Beijing
Changsha
A simple example:
code is as follows |
copy code |
mysql> SELECT * from ' ta '; +----+------+ | id | name | +----+------+ | 1 | a | | 1 | b | | 1 | c | | 1 | d | | 2 | A | | 2 | b | | 2 | c | | 3 | d | +----+------+ 8 rows in Set (0.00 sec) mysql> SELECT ' id ', -> group_concat (' name ') -> FRO M ' Ta ' -> GROUP by ' id '; +----+----------------------+ | id | Group_concat (' name ') | +----+----------------------+ | 1 | A c b d | | 2 | A c B | | 3 | d | +----+----------------------+ 3 rows in Set (0.03 sec) |