类似于Redshift中Listagg的功能

时间:2017-05-15 09:56:17

标签: mysql postgresql amazon-redshift

有人可以建议我如何根据Redshift中的一个特定用户ID将多行合并到一列中。我使用了Listagg函数,但当我在Redshift中将百万行与大小限制错误结合使用时,Listagg会中断。

This is the original table

我想要这样的事情: This is what I want but without using Listagg

我一直在使用以下查询,但Listagg超出限制时会中断

SELECT  id,
        LISTAGG(dest_id, '->')
           WITHIN GROUP (ORDER BY arriving_time) 
           OVER (PARTITION BY ID) AS ROUTES,
        CASE
           WHEN arriving_time IS NOT NULL
           THEN 1
           ELSE 0
        END AS arrived,
        CASE
           WHEN departing_time IS NOT NULL 
           THEN 1
           ELSE 0
        END AS departed,
        row_number()
           OVER (PARTITION BY id ORDER BY departing_time)
           AS RNK

有人可以建议我更好地实现这一目标。

0 个答案:

没有答案