在PostgreSQL的一列中连接字符串

问题描述

我正在尝试转换下表:

id  another_id_1 another_id_2  remarks
1   34.         151.         good
2.  34.         151.         okay
3.  34.         152.         bad
4.  34.         153.         very good
5.  34          153          okay
6.  34          154          good
7.  34          155          bad

进入

another_id_1 another_id_2 remarks
34.          151.         good,okay
34.          152.         bad
34.          153          very good,okay
34.          154          good
34           155          bad

下表使用postgresql语句:

有没有办法实现这一目标,我尝试过的一切似乎都没有效果

解决方法

尽管与您的数据不一致,但我认为您希望进行汇总:

select another_id_1,another_id_2,string_agg(remarks,',' order by id) as remarks
from t
group by another_id_1,another_id_2;

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...