测试版本:8.0.15
数据库数据:
1. 查询json中某个字段 精准查询
SELECT * FROM `tb_json` WHERE JSON_EXTRACT(`Remarks`, '$.name') = 'zhangsan';
或者
SELECT * FROM `tb_json` WHERE JSON_CONTAINS(Remarks,JSON_OBJECT('name','zhangsan'));
结果:
2.查询嵌套对象某个字段 精准查询
SELECT * FROM `tb_json` WHERE JSON_EXTRACT(`Remarks`, '$.address.city') = 'rizhao';
结果:
3.查询json中某个字段 模糊查询
SELECT * FROM `tb_json` WHERE JSON_EXTRACT(`Remarks`, '$.name') LIKE '%zhangsan%';
SELECT * FROM `tb_json` WHERE JSON_EXTRACT(`Remarks`, '$.age') >= 25;
结果: