Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the differences between length and char_length in mysql

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly shows you "what are the differences between length and char_length in mysql". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn "what is the difference between length and char_length in mysql".

Length: is to calculate the length of a field. A Chinese character is counted as three characters, and a number or letter as a character.

Char_length: whether a Chinese character or a number or a letter is a character

Group_concat function in MySQL

The complete syntax is as follows:

Group_concat ([DISTINCT] the field to be connected [Order BY ASC/DESC sort field] [Separator 'delimiter'])

For example, query the following data select * from aa

+-+ +

| | id | name |

+-+ +

| | 1 | 10 |

| | 1 | 20 |

| | 1 | 20 |

| | 2 | 20 |

| | 3 | 200 | |

| | 3 | 500 |

+-+ +

Group by id, print the values of the name field on a line, separated by commas (default)

Select id,group_concat (name) from aa group by id

+-+ +

| | id | group_concat (name) |

+-+ +

| | 1 | 10, 20, 20, 20 |

| | 2 | 20 |

| | 3 | 200500 | |

+-+ +

3 rows in set (0.00 sec)

If they are not grouped, they will be grouped together into a string | 1 | 10 magi 20 pas 20 pas 20, 200500 |

So group_concat actually means literally according to the function itself, it requires you to group first and then put together the data corresponding to the same group.

This is delimited by the; sign.

Select id,group_concat (name separator';') from aa group by id

Group by id and print the values of the de-redundant name fields on one line

Select id,group_concat (distinct name) from aa group by id

+-- +

| | id | group_concat (distinct name) |

+-- +

| | 1 | 100.20 |

| | 2 | 20 |

| | 3 | 200500 | |

+-- +

3 rows in set (0.00 sec)

Group the values in id, print the values of the name field on one line, separated by commas, and sort them in reverse order in name

The above is all the content of the article "what is the difference between length and char_length in mysql". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report