2016-09-12 4 views
0

У меня есть огромный стол, как это:Создание Squential данных из таблицы в PostgreSQL

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 

ли есть SQL-запрос, который я могу сделать в Postgres (Greenplum)?

ответ

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; 
+0

Первый работает в Greenplum. Спасибо, это именно то, что мне нужно. – Ash