1、trans_array实现
select
b1.item_id,
b2.product_info
from(
select
product_id as product_list
from table_1
where product_id is not null and length(product_id)>1
)b1
LATERAL VIEW EXPLODE(split(b1.product_list, '###')) b2 AS product_info
2、group by 字符串连接操作
select
user_id
,concat_ws(',', collect_set(leaf_name)) as leaf_names
,concat_ws(',', collect_list(leaf_name)) as leaf_names
,count(*) as cnt
from table_1
group by user_id
主意:collect_set 返回不重复的集合;collect_list返回重复的集合
另外concat_ws也可以不在group by中使用,比如:
select concat_ws(',', 'a', 'b', 'c') from dual
# 输出:a,b,c
concat是用在非goup by 场景,如:
select concat('a', '
', 'b', ' ', 'c', ',', 'd'))
#测试
select
--replace(info, ' ', '')
regexp_replace(info, ' ', '')
,regexp_replace(info, '( |
|###| )', '')
from(
select concat('a', '
', 'b', ' ', 'c', ' ', '测试###a c,华尔街') as info
)a