当前位置:网站首页>String splicing function of MySQL
String splicing function of MySQL
2022-07-03 01:34:00 【Maple Leaf pear flower】
MySQL String concatenation of has three functions
- CONCAT(str1,str2,…)
- CONCAT_WS(separator,str1,str2,…)
- GROUP_CONCAT(expr)
These three functions have their own functions , Now test to see what the effect looks like
Prepare data sheets
CREATE TABLE `user_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`age` int(3) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
Prepare the data
id | name | age |
---|---|---|
1 | Ana | 24 |
2 | Ame | 24 |
3 | Clid | 27 |
4 | Dave | 27 |
5 | Eva | 27 |
test
CONCAT、CONCAT_WS In fact, it's almost , Namely CONCAT_WS You can set the separator by yourself , And these two fields are the data of the same row .
Use CONCAT
select CONCAT(name,age) as result from user_info
result
result
Ana27
Ame24
Clid24
Dave24
Eva24
Use CONCAT_WS
select CONCAT_WS(':',name,age) as result from user_info
result
result
Ana:27
Ame:24
Clid:24
Dave:24
Eva:24
Use GROUP_CONCAT, This can aggregate multiple lines into one line , Also more commonly used
select GROUP_CONCAT(name) as result from user_info
result
result
Ana,Ame,Clid,Dave,Eva
You can also group and aggregate
select GROUP_CONCAT(name) as result,age from user_info GROUP BY age
result
result age
Ame,Clid,Dave,Eva 24
Ana 27
These three functions are commonly used , But I just briefly demonstrate this function , In depth, you can check other information .
边栏推荐
- Button wizard play strange learning - automatic return to the city route judgment
- leetcode 2097 — 合法重新排列数对
- Basic remote connection tool xshell
- Why can't the start method be called repeatedly? But the run method can?
- [androd] module dependency replacement of gradle's usage skills
- The latest analysis of tool fitter (technician) in 2022 and the test questions and analysis of tool fitter (technician)
- [technology development-23]: application of DSP in future converged networks
- MySQL - database query - basic query
- Now that the teenager has returned, the world's fireworks are the most soothing and ordinary people return to work~
- [Androd] Gradle 使用技巧之模块依赖替换
猜你喜欢
Scheme and practice of cold and hot separation of massive data
[androd] module dependency replacement of gradle's usage skills
[机缘参悟-36]:鬼谷子-飞箝篇 - 面对捧杀与诱饵的防范之道
什么是调。调的故事
海量数据冷热分离方案与实践
[C language] detailed explanation of pointer and array written test questions
How is the mask effect achieved in the LPL ban/pick selection stage?
Expérience de recherche d'emploi d'un programmeur difficile
Leetcode 2097 - Legal rearrangement of pairs
C application interface development foundation - form control (3) - file control
随机推荐
openresty 缓存
C#应用程序界面开发基础——窗体控制(4)——选择类控件
【第29天】给定一个整数,请你求出它的因子数
Leetcode 2097 - Legal rearrangement of pairs
Why can't the start method be called repeatedly? But the run method can?
Kivy tutorial - example of using Matplotlib in Kivy app
并发编程的三大核心问题 -《深入理解高并发编程》
High resolution network (Part 1): Principle Analysis
Learn the five skills you need to master in cloud computing application development
2022 coal mine gas drainage examination question bank and coal mine gas drainage examination questions and analysis
Using tensorboard to visualize the model, data and training process
Give you an array numbers that may have duplicate element values. It was originally an array arranged in ascending order, and it was rotated once according to the above situation. Please return the sm
What operations need attention in the spot gold investment market?
MySQL basic usage 02
[untitled]
[Androd] Gradle 使用技巧之模块依赖替换
Pytest learning notes (12) -allure feature · @allure Step () and allure attach
Is there anything in common between spot gold and spot silver
MySQL --- 数据库查询 - 条件查询
Test shift right: Elk practice of online quality monitoring