14 query techniques in MYSQL

1.group_concat

In our daily work, group bythere 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_concatfunctions.

For example:

select name,group_concat(code) from `user` group by name;

Results of the:

Using group_concatfunctions, 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࿱

Guess you like

Origin blog.csdn.net/WXF_Sir/article/details/131131043