HiveSQL最近7/30日各品牌复购率
生活随笔
收集整理的這篇文章主要介紹了
HiveSQL最近7/30日各品牌复购率
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
最近7/30日各品牌復購率
| 統計周期 | 統計粒度 | 指標 | 說明 |
| 最近7、30日 | 品牌 | 復購率 | 重復購買人數占購買人數比例 |
1.表結構
?2.數據來源
?實現1:
(1) 將每個用戶購買每個品牌的次數進行聚合user_tm_count
select user_id,tm_id,tm_name,sum(order_count_7d) user_tm_countfrom dws_trade_user_sku_order_ndwhere dt = '2020-06-14'group by user_id, tm_id, tm_name?
(2)按品牌分組用大于等于2的user_tm_count÷大于等于1的user_tm_count
selecttm_id,tm_name,sum(`if`(user_tm_count>=2,1,0)) / sum(`if`(user_tm_count>=1,1,0)) from (select user_id,tm_id,tm_name,sum(order_count_7d) user_tm_countfrom dws_trade_user_sku_order_ndwhere dt = '2020-06-14'group by user_id, tm_id, tm_name)t1 group by tm_id,tm_name?(3)將7、30天數據合并
select recent_days,tm_id,tm_name,sum(`if`(user_tm_count >= 2, 1, 0)) / sum(`if`(user_tm_count >= 1, 1, 0)) from (select recent_days,user_id,tm_id,tm_name,sum(`if`(recent_days = 7, order_count_7d, order_count_30d)) user_tm_countfrom dws_trade_user_sku_order_nd lateral view explode(array(7, 30)) tmp as recent_dayswhere dt = '2020-06-14'group by recent_days, user_id, tm_id, tm_name) t1 group by recent_days,tm_id, tm_name select'2020-06-14' dt,recent_days,tm_id,tm_name,cast(sum(if(order_count>=2,1,0))/sum(if(order_count>=1,1,0)) as decimal(16,2)) from (select'2020-06-14' dt,recent_days,user_id,tm_id,tm_name,sum(order_count) order_countfrom(selectrecent_days,user_id,tm_id,tm_name,case recent_dayswhen 7 then order_count_7dwhen 30 then order_count_30dend order_countfrom dws_trade_user_sku_order_nd lateral view explode(array(7,30)) tmp as recent_dayswhere dt='2020-06-14')t1group by recent_days,user_id,tm_id,tm_name )t2 group by recent_days,tm_id,tm_name;總結
以上是生活随笔為你收集整理的HiveSQL最近7/30日各品牌复购率的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 史上最权威的人工智能学习网站推荐
- 下一篇: nfcwriter下载 ios_iOS、