当前位置:网站首页>Concat and concat_ Ws() differences and groups_ Use of concat() and repeat() functions
Concat and concat_ Ws() differences and groups_ Use of concat() and repeat() functions
2022-07-03 14:13:00 【Big data Wang】
1 :concat Function can connect one or more strings , Such as
select concat('10');//10
select concat('11','22','33');//1122332:concat Function when connecting strings , As long as one of them is NULL, Then it will return to NULL
select concat('11','22',null);//null3:concat_ws() function ,
Express concat with separator, That is, string connection 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*22and concat The difference is , concat_ws When the function is executing , Not because NULL Value NULL
4:
group_concat()
Available row to column
The complete grammar is as follows :
group_concat([DISTINCT] Fields to connect [Order BY ASC/DESC Sort field ] [Separator ‘ Separator ’])
Example :
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 With id grouping , hold name The value of the field is printed on one line , Comma separated ( Default )
select id,group_concat(name) from aa group by id;
2 With id grouping , hold name The value of the field is printed on one line , Semicolons separate
select id,group_concat(name separator ';') from aa group by id;
3 With id grouping , Remove redundant name The value of the field is printed on one line , Comma separated
select id,group_concat(distinct name separator ';') from aa group by id;
4 With id grouping , hold name The value of the field is printed on one line ,* No separation , With name Reverse order
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;

边栏推荐
- Toast UI editor (editor allows you to edit your markup document using text or WYSIWYG, with syntax highlighting, scrolling synchronization, real-time preview and chart functions.)
- 牛客网:过河卒
- Fabric. JS document
- Why are grass-roots colleges and universities with "soil and poverty" called "Northeast small Tsinghua"?
- FPGA test method takes mentor tool as an example
- QT learning 23 layout manager (II)
- MIL-100( Fe) 包裹小分子阿司匹林形成[email protected](Fe)|甘草次酸修饰金属有机框架材料UiO-66-NH2(简称UiO-66-NH2-GA)
- Invalid Z-index problem
- jvm-类加载
- Redis:字符串類型數據的操作命令
猜你喜欢

Exercise 8-7 string sorting

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

Current situation, analysis and prediction of information and innovation industry

Exercise 10-6 recursively find Fabonacci sequence

7-10 calculate salary

28: Chapter 3: develop Passport Service: 11: define attributes in the configuration file, and then obtain them in the code;

Why are grass-roots colleges and universities with "soil and poverty" called "Northeast small Tsinghua"?

JVM object lifecycle

消息订阅与发布

Qt学习23 布局管理器(二)
随机推荐
QT learning 22 layout manager (I)
Installation impression notes
RocksDB LRUCache
Back to top implementation
JVM runtime data area
[acnoi2022] guess numbers
Duet date picker (time plug-in that can manually enter the date)
Why are grass-roots colleges and universities with "soil and poverty" called "Northeast small Tsinghua"?
Qt学习24 布局管理器(三)
Mysql:insert date:sql error [1292] [22001]: data truncation: incorrect date value:
Formation of mil-100 (FE) coated small molecule aspirin [email protected] (FE) | glycyrrhetinic acid modified metal organ
Qt学习22 布局管理器(一)
Redis:字符串類型數據的操作命令
牛客网:过河卒
Implementation of Muduo asynchronous logging
【吉林大学】考研初试复试资料分享
Collection of mobile adaptation related articles
jvm-对象生命周期
Interface for querying IP home
核酸修饰的金属有机框架药物载体|PCN-223金属有机骨架包载Ad金刚烷|ZIF-8包裹阿霉素(DOX)