当前位置:网站首页>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
边栏推荐
- prometheus-federation-tls加密
- C#的访问修饰符,声明修饰符,关键字有哪些?扫盲篇
- Advanced multi-threading (CountDownLatch, deadlock, thread-safe collection class)
- The calculation and source code of the straight line intersecting the space plane
- 空间顶点到平面的距离计算的证明及其源码
- debian 问题
- Mobile phone side scroll to page to specify location
- 华为发布“十大发明”,包含计算、智能驾驶等新领域
- Multithreading basics (multithreaded memory, security, communication, thread pools and blocking queues)
- schur completement
猜你喜欢

Required request body is missing problem solving

The CTO said I was not advised to use SELECT *, why is that?

Test Development Engineer Growth Diary 017 - The Life Cycle of a Bug

As a test leader, examine several aspects of job candidates

prometheus-tls加密

Advanced multi-threading (lock strategy, spin+CAS, Synchronized, JUC, semaphore)

空间平面相交的直线的计算及其源码

New breakthrough in artificial muscle smart materials

DHCP原理与配置

Proof of distance calculation from space vertex to plane and its source code
随机推荐
空间顶点到直线的距离计算及其源码
Test Development Engineer Growth Diary 001 - Some Introduction to Agile Testing, CI/CD/CT, DecOps
AI can identify race from X-rays, but no one knows why
阿里一面:多线程顺序运行有多少种方法?
B站崩了,如果是你是那晚负责的开发人员你会怎么做?
numpy 多维数组ndarray的详解
使用 Grafana 的 Redis Data Source 插件监控 Redis
schur completement
proftpd 配置文件说明
DHCP principle and configuration
Electron之初出茅庐——搭建环境并运行第一个程序
Headline 2: there are several kinds of common SQL errors in MySQL usage?
Advanced multi-threading (CountDownLatch, deadlock, thread-safe collection class)
When does MySQL use table locks and when does it use row locks?
STL源码剖析:class template explicit specialization代码测试和理解
prometheus-federation-tls加密
Advanced multi-threading (lock strategy, spin+CAS, Synchronized, JUC, semaphore)
iptables命令
头条二面:MySQL中有几种常见的 SQL 错误用法?
阿里二面:列出 Api 接口优化的几个技巧