with tmp_order as ( select user_id, order_stats_struct.sku_id sku_id, order_stats_struct.order_count order_count from dws_user_action_daycount lateral view explode(order_detail_stats) tmp as order_stats_struct where date_format(dt,'yyyy-MM')=date_format('2021-08-16','yyyy-MM') ), tmp_sku as ( select id, tm_id, category1_id, category1_name from dwd_dim_sku_info where dt='2021-08-16' ) insert into table ads_sale_tm_category1_stat_mn select tm_id, category1_id, category1_name, sum(if(order_count>=1,1,0)) buycount, sum(if(order_count>=2,1,0)) buyTwiceLast, sum(if(order_count>=2,1,0))/sum( if(order_count>=1,1,0)) buyTwiceLastRatio, sum(if(order_count>=3,1,0)) buy3timeLast , sum(if(order_count>=3,1,0))/sum( if(order_count>=1,1,0)) buy3timeLastRatio , date_format('2021-08-16' ,'yyyy-MM') stat_mn, '2021-08-16' stat_date from ( select tmp_order.user_id, tmp_sku.category1_id, tmp_sku.category1_name, tmp_sku.tm_id, sum(order_count) order_count from tmp_order join tmp_sku on tmp_order.sku_id=tmp_sku.id group by tmp_order.user_id,tmp_sku.category1_id,tmp_sku.category1_name,tmp_sku.tm_id )tmp group by tm_id, category1_id, category1_name
时间: 2024-04-18 15:33:05 浏览: 149
ssah.rar_ajax_struct ajax_struct+spring
这段代码是一个SQL插入语句,将计算得到的数据插入到表 "ads_sale_tm_category1_stat_mn" 中。首先,使用子查询 "tmp_order" 从表 "dws_user_action_daycount" 中选择特定日期('2021-08-16')的用户订单统计数据。然后,使用子查询 "tmp_sku" 从表 "dwd_dim_sku_info" 中选择特定日期('2021-08-16')的SKU信息。接下来,将两个子查询的结果进行连接,并按照用户、分类ID、分类名称和品牌ID进行分组。最后,根据分组结果计算购买次数、购买两次以上的比例、购买三次以上的比例,并将结果插入到目标表中。
阅读全文