如何使用POSTGRESQL将群组的结果转换为json?

问题描述 投票:0回答:1

我有以下问题:如果我在表中有此数据:

enter image description here

如何获得这样的结果:

enter image description here

如果结果是这样的json,对我来说将是相同的:

enter image description here

谢谢!

sql json postgresql aggregate
1个回答
0
投票

要获取汇总的JSON,您可以使用jsonb_object_agg()

select users, jsonb_object_agg(day, polls)
from data
group by users;

Online example

© www.soinside.com 2019 - 2024. All rights reserved.