当前位置:网站首页>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
边栏推荐
- Test Development Engineer Growth Diary 001 - Some Introduction to Agile Testing, CI/CD/CT, DecOps
- Selenium02
- Upload file -- file type, picture type, document type, video type, compressed package type
- RAID disk array
- 千万级数据量的表,怎样最快速度查询?
- 计算矩阵的逆源码(使用伴随矩阵,3×3的矩阵)
- Proftpd配置文件
- Redis download and installation
- prometheus-Federation机制配置
- openstack删除计算节点
猜你喜欢

不会吧,Log4j 漏洞还没有完全修复?

LVM and disk quotas

Required request body is missing problem solving

向量三重积的等式推导证明

Polygon 3D(三维平面多边形)的法向量的计算(MeshLab默认的计算)

MySQL什么时候用表锁,什么时候用行锁?

Pioneer in Distributed Systems - Leslie Lambert

深度学习:线性回归模型

The introduction of AI meta-learning into neuroscience, the medical effect is expected to improve accurately

AI可通过X光片识别种族,但没人知道为什么
随机推荐
UDP和TCP使用同一个端口,可行吗?
The Geometric Meaning of Vector Cross Product and the Calculation of Modulus
空间顶点到直线的距离计算及其源码
proftpd 配置文件说明
MongoDB - Introduction, Data Types, Basic Statements
The usage of window.open(), js opens a new form
Test Development Engineer Growth Diary 017 - The Life Cycle of a Bug
和AI一起玩儿剧本杀:居然比我还入戏
The calculation of the determinant of the matrix and its source code
识别“数据陷阱”,发现数据的可疑之处
New material under the plastic restriction order - polylactic acid (PLA)
上传文件--文件类型大全,图片类型,文档类型,视频类型,压缩包类型
prometheus-tls加密
深度学习:线性回归模型
Rodrigues:旋转矩阵的向量表达
Network Protocol 03 - Routing and NAT
debian problem
STL source code analysis: conceptual understanding of iterators, and code testing.
限塑令下的新材料——聚乳酸(PLA)
Required request body is missing 问题解决