Return 单行单列多个类别
Return multiple categories in a single row & single column
我有 table 家销售多个类别的商店,我希望 return 每家商店单独一行,在一个单元格中列出类别。
我的table:
store
category
a
clothing
b
supplies
c
food
a
supplies
a
food
b
clothing
我在找什么:
store
category
a
clothing, food, supplies
b
clothing, supplies
c
food
如有任何建议,我们将不胜感激!
下面使用
select store, string_agg(category, ', ') category
from your_table
group by store
如果应用于您问题中的示例数据 - 输出为
我有 table 家销售多个类别的商店,我希望 return 每家商店单独一行,在一个单元格中列出类别。
我的table:
store | category |
---|---|
a | clothing |
b | supplies |
c | food |
a | supplies |
a | food |
b | clothing |
我在找什么:
store | category |
---|---|
a | clothing, food, supplies |
b | clothing, supplies |
c | food |
如有任何建议,我们将不胜感激!
下面使用
select store, string_agg(category, ', ') category
from your_table
group by store
如果应用于您问题中的示例数据 - 输出为