是否存在将先前的ID推入数组的查询,这将导致:
id c_array
-----------------
1 {}
2 {1}
3 {1,2}
4 {1,2,3}
答案 0 :(得分:2)
我认为您希望将array_agg
聚合用作窗口函数。
SELECT
id,
array_agg(id) OVER (ORDER BY id) AS c_array
FROM the_table
答案 1 :(得分:1)
尝试这样
select id, array(select l.id from table1 l where l.id< i.id order by id) as
c_Arr from table1 i