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

MySql merges a field in a record

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

Share

Shulou(Shulou.com)06/01 Report--

One merges a field in a single record: concat ()

For the user table, it is as follows:

Idclassnameage11001zh1821001en1931002cs1841002jp19

If you want to display name and age as a field, there are:

Select id, class, concat (name, ":, age) as name_age from user

Results:

Idclassname_age11001zh:1821001en:1931002cs: 1841002jp: 19

Second, merge some fields in multiple records: group_coacat ()

Still for the above user table, if you group according to grade and merge all name and age into one column, there are:

Select class, group_concat (name, ":", age) as name_age from user group by class

The result is:

Classname_age1001zh:18,en:191002cs:18,jp:19

By default, the group_coacat () method is split with ",". If you want to split with other characters, you can use "separator", such as:

Select class, group_concat (name, ", age separator"; ") as name_age from user group by class

The result is:

Classname_age1001zh:18;en:191002cs:18;jp:19

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

Wechat

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

12
Report