登录 |  注册 |  繁體中文


mysql json操作

分类: 数据库 颜色:橙色 默认  字号: 阅读(718) | 评论(0)

mysql json操作 创建表:

CREATE TABLE `t` (
  `id` int(11) DEFAULT NULL,
  `content` json DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

添加

insert into t values(1,{"age":11,"s":"abc"})

修改

update t set content=json_set(content,'$.age','26','$.b','sss') where id=1;

结果 content={"age":26,"s":"abc","b":"bbb"} 

删除

update t set content =json_remove(content,'$.b')  where id =1;

 结果 content={"age":26,"s":"abc"} 

查询:

select * from tt WHERE content->'$.age'> 20;
#或者
select * from tt where json_extract(content,'$.age') = 24;
#或者
select * from tt WHERE content->'$.age' in (23, 24);
#或者
select * from tt where content= {"age": 18, "from": "beijin", "name": "php3"};



姓 名: *
邮 箱:
内 容: *
验证码: 点击刷新 *   

回到顶部