首页 文章 mysql json数据类型查询

mysql json数据类型查询

发布时间:2019-08-02 16:56:01 作者:Soul-Yang 阅读量:683

现有如下需求,找出mysql 某个字段(json类型)中是否存在某个值:



可以使用 where  json_search()  is not null ,如以下语句

$sql = "SELECT * FROM `fare_template_detail` WHERE json_search(area,'one','75') is not null and template_id = 1 ";

或者

$sql = "SELECT * FROM `fare_template_detail` WHERE json_search(area,'one','%75%') is not null and template_id = 1 ";

以及延伸到json字段中的某个key中查找

$sql = "SELECT * FROM `fare_template_detail` WHERE json_search(area,'one','75',null,"$[0]") is not null and template_id = 1 ";

如 json 中存在key,则是用点

"SELECT * FROM `fare_template_detail` WHERE json_search(area,'one','75',null,'$.list') is not null and template_id = 1";






  
留言
https://blog.key9.cn/
用户登录
您还没有写任何评论内容!
您已经评论过了!
只能赞一次哦!
您已经收藏啦!