版权声明:转载请注明出处 https://blog.csdn.net/zizhilianqiu/article/details/88593143
最近自己装了mysql8.0版本,把一些比较琐碎的字段转成json入库。现有个查询功能。需要通过json里的字段去进行过滤。
比如说我在数据库里存了
{
"phone":"17701880101",
"city_id":12,
"brand_id":7,
"chexi_id":1242,
"car_id":2313,
"account":"xinche",
"brand_name":"宝马",
"city_name":"北京",
"chexi_name":"中级",
"car_name":"德系"
}
我现在需要通过城市进行查询应该如何写?
答案:select * from car where content->'$.city_id' = 12;是不是很简单,只需要你的【字段名->'$.json字段名'】就可以。
更新语句:
update car set content = json_set(content,'$.city_id',11) where id = 1;
是不是很简单!