当前位置:   article > 正文

sql中几个常用的json解析函数_sql json函数

sql json函数

data:代表json格式的字段名
name:代表json中的元素

普通解析

mysql/ADB MYSQL

json_extract(data,’$.name’)

clickhouse

data[‘name’]

特殊字符

mysql

json_extract(data,’$.“name”’)

ADB MYSQL

json_array_get(data,索引)
索引为int型,从0开始,也就是直接解析array中的第几个元素

解析json元素中的列表

mysql

json_extract(data,’$.name[*].author_id’)

AnalyticDB MySQL

json_extract(data,’$.name[0].name1’)

insert into report_data.mall_goods_data
select 
	 g.data_date
	,g.brand
	,replace(json_extract(g.goods_stat,'$.product_base_result.product_name'),'"','') as goods_name
	,replace(replace(json_extract(g.goods_stat,'$.author_result.author_info[*].author_id'),'[',''),']','') as author_id
	,replace(replace(replace(json_extract(g.goods_stat,'$.pay_gmv'),'"',''),',',''),'¥','')*1 as 成交金额
	,case when json_extract(g.goods_stat,'$.comment_num') like '%万"' then replace(replace(replace(json_extract(g.goods_stat,'$.comment_num'),'"',''),',',''),'万','')*10000 else replace(replace(json_extract(g.goods_stat,'$.comment_num'),'"',''),',','')*1 end as 评价数
	,replace(replace(json_extract(g.goods_stat,'$.dh_live_d_o'),'"',''),'%','')*0.01 as 直播间支付转化率
from 
(
	select * from dy_shop.goods_stats where data_date=date_add(curdate(),interval -1 day)
)g 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/代码探险家/article/detail/911294
推荐阅读
相关标签
  

闽ICP备14008679号