我的表格是这样的
<表类>
user_Id
调查
1001
{"你对什么感兴趣;"[游戏]", "你打算如何使用Gamester "; "[玩游戏,看别人玩,和其他玩家联系]"}
1001
{"你对什么感兴趣;"[优惠券]", "你打算如何使用Gamester "; "[看别人玩]"}
1001
{"你对什么感兴趣;"[游戏]", "你打算如何使用Gamester "; "[玩游戏]"}
表类>
您的json数据数组在How do you plan to use Gamester?
属性是错误的。因为您存储的是字符串而不是值数组。
按如下所示替换所有值:
来源格式:"[Play games, Watch other people play, Connect with other gamers]"
要求格式:["Play games", "Watch other people play", "Connect with other gamers"]
修复数据后,您可以使用jsonb_path_query函数并返回所需属性的值列表,然后对它们进行分组。
with cte_plan as (
select
jsonb_path_query(survey, '$."How do you plan to use Gamester?"[*]') as option
from my_table
)
select option, count(option) from cte_plan group by option;
结果
<表类>选择 数 tbody><<tr>看别人玩 2 玩游戏 2 与其他玩家连接 1 表类>