当前位置:网站首页>sql concat()函数
sql concat()函数
2022-07-30 05:50:00 【饿饿好饿】
1.concat()
concat()函数用于将两个字符串连接起来,形成一个单一的字符串
eg: employee_tbl
id
name
work_date
daily
1
John
2007-01-24
250
2
Ram
2007-05-27
270
sql:
SELECT CONCAT(id, name, work_date) FROM employee_tbl;
结果:
CONCAT(id, name, work_date)
1John2007-01-24
2Ram2007-05-27
2.concat_ws()
使用方法:concat_ws(separator ,str2,str2,…)
concat_ws()代表concat with separator,是concat()函数的特殊形式。
第一个参数是其他参数的分隔符,分隔符的位置要放在两个字符串连接的位置之间。分割符可以是一个字符串,也可以是其他参数
注意:如果分隔符为NULL,那么结果也为NULL,函数会忽略任何分隔符参数后的NULL值
eg:
select concat_ws(',','11','22','33');
结果:
concat_ws(‘,’,‘11’,‘22’,‘33’)
11,22,33
eg:
select concat_ws(',','11','22',NULL);
结果:
concat_ws(‘,’,‘11’,‘22’,NULL)
11,22
3.group_concat()
完整的语法如下:
group_concat([DISTINCT] 要连接的字段 [Order BY ASC/DESC 排序字段] [Separator ‘分隔符’])
eg:
id
name
1
10
1
20
2
10
2
20
3
200
3
500
sql: 以id分组,把name字段的值打印在一行,分号分隔
select id,group_concat(name separator ';') from aa group by id;
结果:
id
name
1
10;20
2
10;20
3
200;500
边栏推荐
- Proftpd配置文件
- matlab机器学习_01
- Linx common directory & file management commands & VI editor usage introduction
- Selenium01
- Playing script killing with AI: actually more involved than me
- 限塑令下的新材料——聚乳酸(PLA)
- STL源码剖析:class template explicit specialization代码测试和理解
- 大飞机C919都用了哪些新材料?
- Test Development Engineer Growth Diary 018 - Record of Required Questions for Test Interview (Continuous Update)
- Rodrigues: vector representation of rotation matrices
猜你喜欢
随机推荐
Is it possible to use the same port for UDP and TCP?
The calculation of the determinant of the matrix and its source code
The introduction of AI meta-learning into neuroscience, the medical effect is expected to improve accurately
window.open()的用法,js打开新窗体
向量的导数运算和向量叉乘以及点乘的导数运算
idea built-in translation plugin
debian problem
Redis下载与安装
From catching up to surpassing, domestic software shows its talents
相机坐标系,世界坐标系,像素坐标系三者转换,以及OPENGLDEFocal Length和Opengl 的 Fov转换
阿里二面:Sentinel vs Hystrix 对比,如何选择?
STL源码剖析:临时对象的代码测试和理解
MongoDB-CUD without R
The newcomer deleted data by mistake, and the team leader skillfully used MySQL master-slave replication to delay the recovery of losses
向量三重积的等式推导证明
Electron之初出茅庐——搭建环境并运行第一个程序
识别“数据陷阱”,发现数据的可疑之处
AI可通过X光片识别种族,但没人知道为什么
iptables命令
When does MySQL use table locks and when does it use row locks?








