当前位置:网站首页>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 .
边栏推荐
- [day 29] given an integer, please find its factor number
- 数学知识:Nim游戏—博弈论
- kivy教程之在 Kivy App 中使用 matplotlib 的示例
- 不登陆或者登录解决oracle数据库账号被锁定。
- [FPGA tutorial case 6] design and implementation of dual port RAM based on vivado core
- [C language] detailed explanation of pointer and array written test questions
- 如今少年已归来,人间烟火气最抚凡人心 复工了~
- The latest analysis of tool fitter (technician) in 2022 and the test questions and analysis of tool fitter (technician)
- Scheme and practice of cold and hot separation of massive data
- 2022 cable crane driver examination registration and cable crane driver certificate examination
猜你喜欢
Expérience de recherche d'emploi d'un programmeur difficile
电信客户流失预测挑战赛
[Arduino experiment 17 L298N motor drive module]
Niu Ke swipes questions and clocks in
[机缘参悟-36]:鬼谷子-飞箝篇 - 面对捧杀与诱饵的防范之道
leetcode刷题_两数之和 II - 输入有序数组
[QT] encapsulation of custom controls
Basis of information entropy
MySQL --- 数据库查询 - 条件查询
C#应用程序界面开发基础——窗体控制(1)——Form窗体
随机推荐
Pytest learning notes (12) -allure feature · @allure Step () and allure attach
Machine learning terminology
MySQL foundation 05 DML language
The meaning of wildcard, patsubst and notdir in makefile
[C language] detailed explanation of pointer and array written test questions
The latest analysis of tool fitter (technician) in 2022 and the test questions and analysis of tool fitter (technician)
C#应用程序界面开发基础——窗体控制(1)——Form窗体
MySQL foundation 07-dcl
Expérience de recherche d'emploi d'un programmeur difficile
MySQL - database query - basic query
Basic concept and implementation of overcoming hash
如今少年已归来,人间烟火气最抚凡人心 复工了~
Top ten regular spot trading platforms 2022
看完这篇 教你玩转渗透测试靶机Vulnhub——DriftingBlues-9
Androd Gradle 对其使用模块依赖的替换
The difference between tail -f, tail -f and tail
2022 Jiangxi Provincial Safety Officer B certificate reexamination examination and Jiangxi Provincial Safety Officer B certificate simulation examination question bank
Create your first Kivy program Hello word (tutorial includes source code)
數學知識:臺階-Nim遊戲—博弈論
Kivy教程大全之 创建您的第一个kivy程序 hello word(教程含源码)