concat(),concat_ws(),group_concat()

hive中的concat函数

concat函数有三种:

1、concat()

2、concat_ws()

3、group_concat()

 

concat(str1,str2,str3)

连接所有字符串,如果有一个参数是null则返回null

concat('a','b','c')  -----'abc'

concat('a','b',null)------null

 

concat_ws('分隔符',str1,str2)

 

concat的特殊格式,表示concat with separator ,两个参数之间加上特殊的分隔符,返回的是用制定分隔符连接参数的字符串。如果分隔符为null则返回null,如果参数为null则忽略该参数

concat('/','2022','4','28') -------2022/4/28

concat(':','22','17',null) ----------22:17

concat(null,'22','17')   ------------null

 

group_concat(str1,[order by str3],[separator '分隔符'])

把相同组的字符串以特定的分隔符连接为一行

 数据

id|name

1|bob

1|anna

1|helan

2|tom

2|baby

2|tom

按id分组把name连为一行

select id,group_concat(name)

1|bobannahelan

2|tombabytom

按id分组把name连为一行,并按升序排序

select id,group_concat(name ordeer by name asc)

1|annabobhelan

2|babytomtom

按id分组,name去重并连为一行,按name升序,并用逗号分隔

select id,group_concat(distinct name order by name asc separator ',')

1|anna,bob,helan

2|baby,tom

 

posted @   虾卡辣卡~  阅读(153)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
点击右上角即可分享
微信分享提示