我有一个蜂巢表
create table abc ( id int, channel string, time int );
insert into table abc values
(1,'a', 12),
(1,'c', 10),
(1,'b', 15),
(2,'a', 15),
(2,'c', 12),
(2,'c', 7);
我希望结果表看起来像这样-
id , journey
1, c->a->b
2, c->c->a
journey
列按id
我尝试过
select id , concat_ws(">", collect_list(channel)) as journey
from abc
group by id
但它不保留顺序。
答案 0 :(得分:0)
使用子查询和按时间排序(以保留顺序),然后在外部查询中使用带有group by子句的collect_list。
hive> select id , concat_ws("->", collect_list(channel)) as journey from
(
select * from abc order by time
)t
group by id;
+-----+----------------+--+
| id | journey |
+-----+----------------+--+
| 1 | 'c'->'a'->'b' |
| 2 | 'c'->'c'->'a' |
+-----+----------------+--+