Postgresql 如何聚合Postgres表以使ID唯一并在数组中收集列值?
我不知道如何调用我正在尝试做的事情,所以尝试查找它并没有很好的效果。我想基于一列聚合我的表,并将另一列中的所有行按唯一ID折叠成一个数组Postgresql 如何聚合Postgres表以使ID唯一并在数组中收集列值?,postgresql,Postgresql,我不知道如何调用我正在尝试做的事情,所以尝试查找它并没有很好的效果。我想基于一列聚合我的表,并将另一列中的所有行按唯一ID折叠成一个数组 | ID | some_other_value | ------------------------- | 1 | A | | 1 | B | | 2 | C | | .. | ... | 归来 | ID | values_array
| ID | some_other_value |
-------------------------
| 1 | A |
| 1 | B |
| 2 | C |
| .. | ... |
归来
| ID | values_array |
-------------------------
| 1 | {A, B} |
| 2 | {C} |
对不起,解释得不好,我这里真的缺乏词汇。如果您能帮助编写一个查询以实现示例中的内容,我们将不胜感激 参见文档
SELECT
id,
array_agg(some_other_value)
FROM
the_table
GROUP BY
id;
见文件
SELECT
id,
array_agg(some_other_value)
FROM
the_table
GROUP BY
id;
尝试以下方法
select id, array_agg(some_other_value order by some_other_value ) as values_array from <yourTableName> group by id
选择id,array_agg(some_other_值按some_other_值排序)作为按id分组的值数组
您也可以检查。尝试以下操作
select id, array_agg(some_other_value order by some_other_value ) as values_array from <yourTableName> group by id
选择id,array_agg(some_other_值按some_other_值排序)作为按id分组的值数组
你也可以查一下