问题描述
我正在尝试转换下表:
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;