使用sqlite json函数,我想检索附近的值的价值基础

发布于 2025-01-29 05:09:09 字数 388 浏览 3 评论 0原文

可以说我有这个JSON,我想检索名称等于数组键中的Chris的所有年龄值。

{
    "Array": [
        {
            "age": "65",
            "name": "Chris"
        },
        {
            "age": "20",
            "name": "Mark"
        },
        {
            "age": "23",
            "name": "Chris"
        }
    ]
}

该JSON存在于我的数据库内的JSON列中。 这样,我想检索一个年龄栏的年龄为65岁和23岁,因为他们都命名为克里斯(Chris)。

Lets say I have this Json and I would like to retrieve all the age values where the name equals Chris in the Array key.

{
    "Array": [
        {
            "age": "65",
            "name": "Chris"
        },
        {
            "age": "20",
            "name": "Mark"
        },
        {
            "age": "23",
            "name": "Chris"
        }
    ]
}

That Json is present in the Json column inside my database.
by that I would like to retrieve one age column the has the age 65 and 23 because they both named Chris.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云胡 2025-02-05 05:09:09

使用 json_each()table-valuew表格的JSON数组的名称和年龄和 /code> 功能要过滤'Chris'的行,并确保他的年龄:

SELECT json_extract(j.value, '$.name') name, 
       json_extract(j.value, '$.age') age
FROM tablename t JOIN json_each(t.col, "$.Array") j
WHERE json_extract(j.value, '$.name') = 'Chris';

更改col到JSON列的名称。

请参阅

Use json_each() table-valued function to extract all the names and ages from the json array of each row of the table and json_extract() function to filter the rows for 'Chris' and get his age:

SELECT json_extract(j.value, '$.name') name, 
       json_extract(j.value, '$.age') age
FROM tablename t JOIN json_each(t.col, "$.Array") j
WHERE json_extract(j.value, '$.name') = 'Chris';

Change col to the name of the json column.

See the demo.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文