当前位置:网站首页>concat和concat_ws()区别及group_concat()和repeat()函数的使用
concat和concat_ws()区别及group_concat()和repeat()函数的使用
2022-07-03 13:35:00 【大数据小王】
1 :concat 函数可以连接一个或者多个字符串,如
select concat('10');//10
select concat('11','22','33');//1122332:concat函数在连接字符串的时候,只要其中一个是NULL,那么将返回NULL
select concat('11','22',null);//null3:concat_ws()函数,
表示concat with separator,即有分隔符的字符串连接
select concat_ws(',','11','22','33');//11,22,33
select concat_ws('|','11','22','33');//11|22|33
select concat_ws('*','11','22',NULL);//11*22和concat不同的是, concat_ws函数在执行的时候,不会因为NULL值而返回NULL
4:
group_concat()
可用来行转列
完整的语法如下:
group_concat([DISTINCT] 要连接的字段[Order BY ASC/DESC 排序字段] [Separator ‘分隔符’])
例子:
create table aa(
id int,
name VARCHAR(255)
);
insert into aa values(1,10);
insert into aa values(1,10);
insert into aa values(1,20);
insert into aa values(1,30);
insert into aa values(3,30);
insert into aa values(5,60);
insert into aa values(5,90);
insert into aa values(6,990);
1 以id分组,把name字段的值打印在一行,逗号分隔(默认)
select id,group_concat(name) from aa group by id;
2 以id分组,把name字段的值打印在一行,分号分隔
select id,group_concat(name separator ';') from aa group by id;
3 以id分组,把去冗余的name字段的值打印在一行,逗号分隔
select id,group_concat(distinct name separator ';') from aa group by id;
4 以id分组,把name字段的值打印在一行,*号分隔,以name排倒序
select id,group_concat(name order by name desc separator "*") from aa group by id;
eg:
select * from aa;

select id,group_concat(name) from aa group by id;

select id,group_concat(name separator ';') from aa group by id;
select id,group_concat(distinct name separator ';') from aa group by id;

select id,group_concat(name order by name desc separator "*") from aa group by id;

边栏推荐
- Selenium browser (1)
- 可编程逻辑器件软件测试
- Solve the problem of dormitory router campus network sharing login
- How to promote the progress of project collaboration | community essay solicitation
- [bw16 application] instructions for firmware burning of Anxin Ke bw16 module and development board update
- Multi person collaborative data annotation based on Baidu brain easydata from scratch
- Solve MySQL 1045 access denied for user 'root' @ 'localhost' (using password: yes)
- JS Part 2
- Ocean CMS vulnerability - search php
- 叶酸修饰的金属-有机骨架(ZIF-8)载黄芩苷|金属有机骨架复合磁性材料([email protected])|制备路线
猜你喜欢

Use and design of Muduo buffer class

Scroll detection, so that the content in the lower right corner is not displayed at the top of the page, but is displayed as the mouse slides

Multi person collaborative data annotation based on Baidu brain easydata from scratch

信创产业现状、分析与预测

Go language web development series 25: Gin framework: using MD5 to verify the signature for the interface station

Redis:字符串类型数据的操作命令
[email protected])|制备路线"/>叶酸修饰的金属-有机骨架(ZIF-8)载黄芩苷|金属有机骨架复合磁性材料([email protected])|制备路线

Article content typesetting and code highlighting

如何使用lxml判断网站公告是否更新

Redis: operation command of string type data
随机推荐
Qt学习22 布局管理器(一)
Page generation QR code
Windos creates Cordova prompt because running scripts is prohibited on this system
C language standard IO function sorting
Redis:字符串类型数据的操作命令
JS general form submission 1-onsubmit
Scroll detection, so that the content in the lower right corner is not displayed at the top of the page, but is displayed as the mouse slides
JVM family - overview, program counter day1-1
page owner特性浅析
JS Part III
Common mixins
Uio-66-cooh loaded bendamostine | hydroxyapatite (HA) coated MIL-53 (FE) nanoparticles | baicalin loaded manganese based metal organic skeleton material
Comprehensive case of MySQL data addition, deletion, modification and query
Ocean CMS vulnerability - search php
叶酸修饰的金属-有机骨架(ZIF-8)载黄芩苷|金属有机骨架复合磁性材料([email protected])|制备路线
JS input number and standard digit number are compared. The problem of adding 0 to 0
Generate directories from web content
simpleParallax. JS (create poor visual effects for website pictures)
项目协作的进度如何推进| 社区征文
Why are grass-roots colleges and universities with "soil and poverty" called "Northeast small Tsinghua"?