zoukankan      html  css  js  c++  java
  • 【MySQL】根据JSON字段的内容检索查询数据

    查询语句

    • 使用 字段->'$.json属性' 进行查询条件
    • 使用 json_extract 函数查询,json_extract(字段, "$.json属性")
    • 根据json数组查询,用 JSON_CONTAINS(字段, JSON_OBJECT('json属性', "内容"))

    MySQL5.7以上支持JSON的操作,以及增加了JSON存储类型
    一般数据库存储JSON类型的数据会用JSON类型或者TEXT类型

    注意:用JSON类型的话
    1)JSON列存储的必须是JSON格式数据,否则会报错。
    2)JSON数据类型是没有默认值的。

    使用示例:
    1 演示数据

    查询语句

    SELECT * FROM test_event_list  where `subdata` -> '$.page_url' = 'https//www.test.com/123456.html';
    
    select  *  from test_event_list where JSON_CONTAINS(`subdata`, JSON_OBJECT('page_url', "https//www.test.com/123456.html"));
    
    select  *  from test_event_list   where json_extract(subdata,'$.page_url') = 'https//www.test.com/123456.html';
    

    提示: 此方法在大批量数据下查询 缓慢,慎用!

  • 相关阅读:
    hdu 2203 亲和串
    hdu 3999 The order of a Tree
    poj 2299 Ultra-QuickSort
    hdu 1908 Double Queue
    hdu 1556 Color the ball
    hdu 4288 Coder
    hdu 5265 pog loves szh II
    hdu 5058 So easy
    T103763 【模板】矩阵乘法
    T103492 【模板】点双连通分量
  • 原文地址:https://www.cnblogs.com/richerdyoung/p/14271308.html
Copyright © 2011-2022 走看看