Open BruceOuyang opened 2 years ago
mysql 5.7 开始支持 json 相关处理,这里给出几个基础用法
follow https://blog.csdn.net/szxiaohe/article/details/82772881
示例数据(存储在 order 表中 product 字段的 json 字符串):
{ "productId":209, "productName":"P245/55 R19 103S 城市HT产品", "stock":336, "attrInfo":{ "barCode":"18250489", "price":728, "stock":336 } }
格式:
select json_field->'$.filed' as field from table_name;
示例:
select product->'$.productName' as productName from order;
order 表有一个 product 字段,存的是 product 信息的 json 字符串数据
select json_field->'$.filed.itemField' as field from table_name;
select product->'$.attrInfo.barCode' as productName from order;
mysql 5.7 开始支持 json 相关处理,这里给出几个基础用法
示例数据(存储在 order 表中 product 字段的 json 字符串):
1.从 mysql 表字段中,获取 json 某个字段
格式:
示例:
2.多层级
格式:
示例: