array_agg
聚合函数:
-- sample data
with dataset(id, interest) as(
values (1, 'Math'),
(1, 'Poetry'),
(1, 'Art'),
(2, 'Math'),
(2, 'Other')
)
-- query
select id, array_agg(interest) interest
from dataset
group by id
输出:
id | 兴趣 |
---|---|
1 | [数学、诗歌、艺术] |
2 | [数学,其他] |