熱線電話:13121318867

登錄
2023-07-20 閱讀量: 2453
Cda數據分析——Sql淘寶案例(六)消費偏好分析

這個相對于留存分析等相對簡單,附代碼

其中topn是常用的指標分析,而第一段的having是為了防止分母為0,轉化率為null

# 查詢每個商品的瀏覽量、成交量、轉化率
select  item_id,
        sum(if(behavior_type='pv',1,0)) as 瀏覽量,
      sum(if(behavior_type='buy',1,0)) as 成交量,
     sum(if(behavior_type='buy',1,0))/sum(if(behavior_type='pv',1,0)) as 轉化率
from userbehavior_new
group by item_id
having sum(if(behavior_type='pv',1,0)) and sum(if(behavior_type='buy',1,0)) >0;
# 爆款商品:流量top10
select item_id,
       sum(if(behavior_type = 'pv',1,0)) as 流量,
       row_number()over(order by sum(if(behavior_type = 'pv',1,0)) desc) as 排名
from userbehavior_new
group by item_id;
# 暢銷商品:成交top10
select item_id,
       sum(if(behavior_type = 'buy',1,0)) as 流量,
       row_number()over(order by sum(if(behavior_type = 'buy',1,0)) desc) as 排名
from userbehavior_new
group by item_id;



0.0000
0
關注作者
收藏
評論(0)

發表評論
日韩人妻系列无码专区视频,先锋高清无码,无码免费视欧非,国精产品一区一区三区无码