MySQL5.7 如何查询某个值是否在 JSON 类型的字段中呢。
表结构类似这样:
create table xxxtable ( id bigint(22) auto_increment comment '主键 id' primary key, waring_value_msg json not null comment '', names_virtual varchar(20) as (json_unquote(json_extract(`waring_value_msg`, '$.warnMonth'))) ) comment '' charset = utf8; create index device_waring_config_names_virtual_index on tnor.device_waring_config (names_virtual); 表中 json 格式的数据大致如下:
{ "warnMonth": [1,2], "rouleItem": [{ "maxValue": 10, "minValue": 0, "waringMsg": "这是提示信息", "warnMonth": "1" }, { "maxValue": 20, "minValue": 10, "waringMsg": "这是提示信息", "warnMonth": "2" }] } 有什么办法可以通过 SQL 来查询 我给出的 warnMonth 是不是在 JSON 里面呢,类似于这种:
select * from xxxtable where #{warnMonth} in JOSN 中的 warnMonth ; 