Mysql json内容处理sql

一、版本要求

MySql4.7

二、字段类型:

json类型

三、需要虚拟索引

关于需要处理的json字段,创建虚拟索引:

ALTER TABLE wxhk.t_iotdata ADD sn_virtual varchar (32) GENERATED ALWAYS AS (json_extract(DataContent, ‘$.serialNumber’ )) VIRTUAL;

四、查询:

如果查找内容是一介字段只需要前加‘ . ’ s e l e c t j s o n e x t r a c t ( D a t a C o n t e n t , ′ .’ select json_extract(DataContent,' .selectjsonextract(DataContent,.deviceId’) from wxhk.t_iotdata where json_extract(DataContent,’ . d e v i c e I d ′ ) = " x x x " ; 如 果 查 找 内 容 是 多 阶 子 字 段 , 需 要 ‘ .deviceId')="xxx"; 如果查找内容是多阶子字段,需要‘ .deviceId)="xxx";.’后加前面各介父字段名,如下:
select json_extract(DataContent,’ . d e v i c e I n f o . m a c ′ ) f r o m w x h k . t i o t d a t a w h e r e j s o n e x t r a c t ( D a t a C o n t e n t , ′ .deviceInfo.mac') from wxhk.t_iotdata where json_extract(DataContent,' .deviceInfo.mac)fromwxhk.tiotdatawherejsonextract(DataContent,.deviceInfo.mac’)=“xxx”;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值