最简单的复购率求法

零食类商品中复购率top3高的商品

https://www.nowcoder.com/practice/9c175775e7ad4d9da41602d588c5caf3

#复购率top3高
#复购率保留3位小数,近90天内购买它至少两次的人数 ÷ 购买它的总人数
#复购率倒序、商品ID升序排序
select
    product_id,
    round(avg(cnt>1),3) as repurchase_rate 
from (
    select 
    product_id,
    uid,
    count(event_time) as cnt
    from tb_product_info join tb_order_detail using(product_id)
        join tb_order_overall using(order_id)
    where tag ='零食' and status = 1 #零食类商品 
    and datediff(date((select max(event_time) from tb_order_overall)),event_time)<90 #近90天内购买
    group by uid,product_id
) t
group by product_id 
order by repurchase_rate desc,product_id 
limit 3

先找出每一个商品,每人的购买次数。

avg(cnt>1) 是求,判定,购买次数大于1为1,否则为0 ,平均就是复购率了。

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务