当前位置:网站首页>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');//112233
2:concat Function when connecting strings , As long as one of them is NULL, Then it will return to NULL
select concat('11','22',null);//null
3: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*22
and 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;
边栏推荐
- JVM runtime data area
- JVM class loading
- “又土又穷”的草根高校,凭什么被称为“东北小清华”?
- JS first summary
- Webpage connection database ~ simple implementation of addition, deletion, modification and query complete code
- Exercise 10-1 judge the three digits that meet the conditions
- Why don't I have a rookie medal
- fpga阻塞赋值和非阻塞赋值
- Formation of mil-100 (FE) coated small molecule aspirin [email protected] (FE) | glycyrrhetinic acid modified metal organ
- 全局事件总线
猜你喜欢
Redis: redis data structure and key operation commands
QT learning 25 layout manager (4)
QT learning 17 dialog box and its types
消息订阅与发布
Installation impression notes
Exercise 10-3 recursive implementation of exponential functions
Leetcode(4)——寻找两个正序数组的中位数
JVM runtime data area
关于回溯问题中的排列问题的思考(LeetCode46题与47题)
Dlopen() implements dynamic loading of third-party libraries
随机推荐
C library function - qsort()
Exercise 10-6 recursively find Fabonacci sequence
[ACNOI2022]猜数
Exercise 8-8 moving letters
八大排序
全局事件总线
QT learning 25 layout manager (4)
Redis:字符串類型數據的操作命令
GRPC的四种数据流以及案例
中国PETG市场预测及战略研究报告(2022版)
Nucleic acid modified metal organic framework drug carrier | pcn-223 metal organic framework encapsulated ad adamantane | zif-8 encapsulated adriamycin (DOX)
QT learning 22 layout manager (I)
Message subscription and publishing
js . Find the first palindrome string in the array
7-9 find a small ball with a balance
核酸修饰的金属有机框架药物载体|PCN-223金属有机骨架包载Ad金刚烷|ZIF-8包裹阿霉素(DOX)
MySQL data processing value addition, deletion and modification
jvm-对象生命周期
[Jilin University] information sharing of postgraduate entrance examination and re examination
Leetcode(4)——尋找兩個正序數組的中比特數