hive_group

1、concat()

1.1、concat(str1, str2, ...)

user表

id     name
01    test

运行:select concat(id, ',', name)  as  info from user

结果

info
01,test

1.2、concat_ws(separator, str1, str2)

运行 : select concat_ws('_', id, name) as result from user

result
01_test

1.3、group_concat()

 一张角色对应表 role_table

id     role
12     admin
12     presale
13     productManager
13     custManager

运行 : SELECT  id, GROUP_CONCAT(distinct role separator ',' AS  roles FROM role_table GROUP BY id

id          roles
12          admin , presale           
13          productManager , custManager 

 1.4 、 CONCAT_WS(SEPARATOR , collect_set(column))   

        效果和1.3 一样

运行 : select id,concat_ws(',',collect_set(role)) as roles from role_table group by id

id          roles
12          admin , presale           
13          productManager , custManager 

====================================================================

参考:https://www.cnblogs.com/wqbin/p/10266783.html

原文地址:https://www.cnblogs.com/Jomini/p/12527568.html