当前位置:网站首页>mysql 表查询json数据

mysql 表查询json数据

2022-06-25 06:32:00 码农竟在我身边

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"
原网站

版权声明
本文为[码农竟在我身边]所创,转载请带上原文链接,感谢
https://blog.csdn.net/apanpan8126/article/details/125394568

随机推荐