mysql 表查询json数据

mysql 表查询json数据

// An highlighted block
字段attributes的值为
{“desc”:{ “index”:“序号”, “startDate”:“开始日期”, “endDate”:“结束日期”, “ruId”:“发奖规则” }, “name”: “日期配置”, “tips”: “必配”, “type”:JSON, “value”:[{“index”:1,“startDate”:2022-02-15,“endDate”:2024-03-19,“ruId”:“ru_4”}], “variable”: “date_config”, “configType”: “”}
1、查找desc,使用json_extract
select json_extract(attributes,’$.desc’) from TableName
若desc下有多个元素,可使用数组下标,desc[0]/desc[1]取对应元素;若desc下包含多个键值对,则使用desc.key取对应key值
2、替换可使用json_replace,json_set
二者区别
json_set() 若查找的值存在则替换,不存在则插入
json_replace()替换/修改存在的值
替换name的值
update TableName set name=json_set(attributes,’$.name’,‘新的值’)
update TableName set name=json_replace(attributes,’$.name’,‘新的值’)

select * from fa_trade_order  WHERE json_extract(json,'$.status') ="1"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值