insert into jwc(st_num,info) value('131141','{"数学":[95,4],"英语":{"英语上":[87,3],"英语下":[82,3]},"体育":"不及格"}')
//选择“数学”对应的值
select json_extract(info,"$.数学") from jwc where id='131141'
//选择“数学”对应的值
select info->"$.数学" from jwc where id='131141'
select json_keys(info) from jwc
//注意中间elem(95)一定要用字符串形式表示
select * from jwc where json_contains(info,'95','$.数学')
//json_search的第二个参数one表示找一个,all表示找到所有
select * from jwc where json_search(info,'one',"%及格") is not null;
select * from jwc where info->'$.数学[0]'>90;
//对于非列表的值直接扩展成列表
update personal_info set info=json_array_append(info,'$."数学"',4) where id=6;
update personal_info set info=json_array_insert(info,'$."数学"[0]',4) where id=6;
update personal_info set info=json_set(info,'$."数学"',4) where id=6;
update personal_info set info=json_merge(info,'{"提示":"this is a test"}') where id=6;
update personal_info set info=json_replace(info,'$."提示"','this is another test') where id=6;
上述 是关于mysql对json数据类型的操作介绍,下面分析一下json数据类型使用的一些问题。
update personal_info set info=json_replace(info,'$."提示"','this is another test','$."数学"',[94,3]) where id=6;
也就说,对数列和字典的支持还不够。
以上提出的这些缺陷或许是因为我对mysql了解不够深入,或许mysql有相应的解决办法,这里暂时存疑,希望知道的朋友能告知,以上。
http://blog.xqlee.com/article/491.html