gpt4 book ai didi

sql - 查询存储在数据库字段中的字符串中的特定值

转载 作者:行者123 更新时间:2023-11-29 13:22:17 25 4
gpt4 key购买 nike

{"create_channel":"1","update_comm":"1","channels":"*"}

这是我要查询的数据库字段。

如果我想选择所有具有 "create_channel": "1" 的记录,我的查询会是什么样子?和一个 "update_comm": "1"

附加问题:

查看下面的字段:

{"create_channel":"0","update_comm":"0","channels":[{"ch_id":"33","news":"1","parties":"1","questions ":"1","cam":"1","edit":"1","view_subs":"1","invite_subs":"1"},{"ch_id":"18","news":"1","parties":"1","questions ":"1","cam":"1","edit":"1","view_subs":"1","invite_subs":"1"}]}

我将如何找出所有在 News 中的子管理员? , parties , questionsCams部分

最佳答案

您可以使用 the ->> operator以字符串形式返回成员:

select  * 
from YourTable
where YourColumn->>'create_channel' = '1' and
YourColumn->>'update_comm' = '1'

要查找在 channel 33 中有新闻、聚会、问题和摄像头的用户,您可以使用 the @> operator检查 channel 数组是否包含这些属性:

select  *
from YourTable
where YourColumn->'channels' @> '[{
"ch_id":"33",
"news":"1",
"parties":"1",
"questions ":"1",
"cam":"1"
}]';

关于sql - 查询存储在数据库字段中的字符串中的特定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39567813/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com