1.group_concat
In our daily work, group by
there are many scenarios where grouping is used.
For example, you want to count the specific names of users with different names in the user table?
The specific sql is as follows:
select name from `user` group by name;
But what if you want to splice codes with the same name together and put them in another column?
Answer: Use group_concat
functions.
For example:
select name,group_concat(code) from `user` group by name;
Results of the:
Using group_concat
functions, you can easily splice grouped data with the same name together to form a string, separated by 逗号
.
2.char_length
Sometimes we need to get the character 长度
and then proceed based on the length of the character 排序
.
MYSQL provides us with some useful functions, such as: char_length
.
The character length can be obtained through this function.
The sql to get the character length and sort is as follows