【问题标题】:How to search for specific data inside a JSON data at table如何在表中的 JSON 数据中搜索特定数据
【发布时间】:2021-12-15 10:16:09
【问题描述】:

我有一个名为carts 的表,其结构如下:

1   crt_id Primary  bigint(20)      
2   crt_mbr_id      bigint(20)          
3   crt_session_id  varchar(128)    
4   crt_content     text    
5   crt_send_type   int(11)         
6   crt_completed   tinyint(1)          
7   created_at      timestamp           
8   updated_at      timestamp   

crt_content 的数据是这样的:

[{"id":"24","quantity":"1","price":3000,"discounted":3000,"coupon":0}]

现在我需要在crt_content 中搜索号码24。但是我不知道这个sql命令是什么。

那么您介意帮助我了解如何在存储在表中的 JSON 数据中搜索特定数据吗?

【问题讨论】:

标签: php mysql sql json phpmyadmin


【解决方案1】:

您可以在 where 子句中使用如下所示的 JSON_EXTRACT 函数:

JSON_EXTRACT(crt_content, "$.id") = "24"

不过,我想警告您,我不建议将此用于包含大量数据的解决方案。如果您想了解更多关于 JSON 搜索功能的信息,请查看here

【讨论】:

    猜你喜欢
    • 2013-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-05
    相关资源
    最近更新 更多