![](/img/trans.png)
[英]Can you concatenate two strings to create dynamic column names in PostgreSQL?
[英]Concatenate strings in a column in 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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.