当前位置:网站首页>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;

边栏推荐
- Redis:字符串類型數據的操作命令
- Go language unit test 3: go language uses gocovey library to do unit test
- Implementation of Muduo accept connection, disconnection and sending data
- Conversion function and explicit
- 【吉林大学】考研初试复试资料分享
- QT learning 17 dialog box and its types
- 小项目(servelt+jsp+mysql+EL+JSTL)完成一个登录功能的Servlet,具有增删改查的操作。实现登录身份验证,防止非法登录,防止多点登录,记住用户名密码功能。
- JVM class loading
- Webpage connection database ~ simple implementation of addition, deletion, modification and query complete code
- jvm-对象生命周期
猜你喜欢

Programmable logic device software testing

使用vscode查看Hex或UTF-8编码

Scroll detection of the navigation bar enables the navigation bar to slide and fix with no content

Qt学习18 登录对话框实例分析

Vite project commissioning

JS matrix zero

Go language web development series 30: gin: grouping by version for routing

GoLand 2021.1: rename the go project

Rasp implementation of PHP

Qt学习24 布局管理器(三)
随机推荐
Why don't I have a rookie medal
Uniapp tips - scrolling components
GoLand 2021.1: rename the go project
Metal organic framework (MOFs) antitumor drug carrier | pcn-223 loaded with metronidazole | uio-66 loaded with ciprofloxacin hydrochloride(
Spring cup eight school league
MIL-100( Fe) 包裹小分子阿司匹林形成[email protected](Fe)|甘草次酸修饰金属有机框架材料UiO-66-NH2(简称UiO-66-NH2-GA)
QT learning 25 layout manager (4)
Current situation, analysis and prediction of information and innovation industry
从零开始的基于百度大脑EasyData的多人协同数据标注
Windos creates Cordova prompt because running scripts is prohibited on this system
MySQL data processing value addition, deletion and modification
金属有机骨架MIL-88负载阿霉素DOX|叶酸修饰UiO-66-NH2负载阿霉素[email protected]纳米粒子
PhpMyAdmin stage file contains analysis traceability
Formation of mil-100 (FE) coated small molecule aspirin [email protected] (FE) | glycyrrhetinic acid modified metal organ
Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:
信创产业现状、分析与预测
simpleParallax. JS (create poor visual effects for website pictures)
JS shift operators (< <,> > and > > >)
Solve the problem of dormitory router campus network sharing login
Dynamic programming 01 knapsack and complete knapsack