mysql中 提取json字符串日志中的元素:
col_log表:
"{
"$tadata":{
},
"event":"erminate",
"properties":{
"$band":"Redmi",
}
}"
方法一:
select replace(json_extract( json_extract(col_log,'$.properties'),'$.$band'),'"','') band
from tracking.tracking_col_log order by create_time desc;
方法二:
select replace(json_extract( json_extract(replace(col_log,'$',''),'$.band'),'$.band'),'"','') brand
from tracking.tracking_collect_log order by create_time desc;
- $: 调用字符型的key值;
- replace(data,'$','') 替换data字符串中的$符号,为空;
- json_extract(json_data,$. band): 提取json_data中的key-band对应的value值,使用$.band