当前位置:网站首页>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 .
边栏推荐
- MySQL basics 03 introduction to MySQL types
- Mathematical knowledge: divisible number inclusion exclusion principle
- 【第29天】给定一个整数,请你求出它的因子数
- 电信客户流失预测挑战赛
- CF1617B Madoka and the Elegant Gift、CF1654C Alice and the Cake、 CF1696C Fishingprince Plays With Arr
- Basic concept and implementation of overcoming hash
- 数学知识:台阶-Nim游戏—博弈论
- 软考信息系统项目管理师_历年真题_2019下半年错题集_上午综合知识题---软考高级之信息系统项目管理师053
- MySQL foundation 06 DDL
- Common English Vocabulary
猜你喜欢

Soft exam information system project manager_ Real topic over the years_ Wrong question set in the second half of 2019_ Morning comprehensive knowledge question - Senior Information System Project Man

【我的OpenGL学习进阶之旅】关于欧拉角、旋转顺序、旋转矩阵、四元数等知识的整理

Telecom Customer Churn Prediction challenge

Niu Ke swipes questions and clocks in
![[技术发展-23]:DSP在未来融合网络中的应用](/img/2e/f39543a18a8f58b1d341ce72cc4427.png)
[技术发展-23]:DSP在未来融合网络中的应用

Three core issues of concurrent programming - "deep understanding of high concurrent programming"
![[untitled]](/img/fd/f6b90536f10325a6fdeb68dc49c72d.png)
[untitled]

一位苦逼程序员的找工作经历

Androd gradle's substitution of its use module dependency

Pytest learning notes (12) -allure feature · @allure Step () and allure attach
随机推荐
力扣 204. 计数质数
Basic concept and implementation of overcoming hash
LeetCode 987. Vertical order transverse of a binary tree - Binary Tree Series Question 7
数学知识:台阶-Nim游戏—博弈论
【QT】自定义控件的封装
Is there anything in common between spot gold and spot silver
一位苦逼程序员的找工作经历
对非ts/js文件模块进行类型扩充
按键精灵打怪学习-自动回城路线的判断
Telecom Customer Churn Prediction challenge
Top ten regular spot trading platforms 2022
[untitled]
tp6快速安装使用MongoDB实现增删改查
[technology development-23]: application of DSP in future converged networks
C#应用程序界面开发基础——窗体控制(3)——文件类控件
Pytest learning notes (12) -allure feature · @allure Step () and allure attach
2022 Jiangxi Provincial Safety Officer B certificate reexamination examination and Jiangxi Provincial Safety Officer B certificate simulation examination question bank
【面试题】1369- 什么时候不能使用箭头函数?
MySQL basic usage 02
What is tone. Diao's story