我有一张像这样的大桌子:
id eventid timestamp
id1 event1 time1
id1 event2 time2
id2 event1 time3
id2 event4 time4
id1 event4 time6
我想要的是每个用户,其事件按时间排序如下:
id event_sequence(nvarchar)
id1 event1,event2,event4
id2 event1,event4
我是否可以在Postgres(Greenplum)中执行SQL查询?
答案 0 :(得分:1)
嗯。我不知道你是否可以在Greenplum做到这一点。在Postgres中,它看起来像:
select id, string_agg(event, ',' order by timestamp) as events
from t
group by id;
在Greenplum,我认为你需要使用:
select id, array_to_string(array_agg(event, ',' order by timestamp)) as events
from t
group by id;