我有一个名为“ mtn_name”的表,例如-
Id Value
1 Body Repair
1 Gear Repair
1 Gear oil change
2 Body glass Repair
2 Gearbox Repair
2 Oil change
需求查询结果就像
Id Value
1 Body Repair,Gear Repair,Gear oil change
2 Body glass Repair,Gearbox Repair,Oil change
答案 0 :(得分:1)
您可以使用string_agg,它将对所需的字符串进行分组。 示例:
select id,string_agg(Value,',' ORDER BY Value) As group_value
from mtn_name
group by id