表结构如下

CREATE TABLE `test` (
  `exp_setup_grep_property` varchar(255) DEFAULT NULL COMMENT '用户分群下的组对应的属性信息'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

表数据如下

INSERT INTO `test` (`exp_setup_grep_property`) VALUES ('{\"yes\":[0,1,2,3,4,5]}');
INSERT INTO `test` (`exp_setup_grep_property`) VALUES ('{\"yes\":[0,1,2,3,4,5]}');
INSERT INTO `test` (`exp_setup_grep_property`) VALUES ('{\"yes\":[7,8,9]}');
INSERT INTO `test` (`exp_setup_grep_property`) VALUES ('{\"no\":[2,3]}');

查询需求,查询json数据中的yes包含 2的 和 json 的no数组中不包含2的数据

查询SQL如下


SELECT exp_setup_grep_property
from test
where
json_contains(JSON_EXTRACT(cast(exp_setup_grep_property as json), '$.yes'),JSON_ARRAY(2)) = 1
or json_contains(JSON_EXTRACT(cast(exp_setup_grep_property as json), '$.no'),JSON_ARRAY(2)) = 0

 

最后修改于 2022-03-23 17:56:02
如果觉得我的文章对你有用,请随意赞赏
扫一扫支付
上一篇