题解 | #零食类商品中复购率top3高的商品#

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

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

with main as 
(
select
 pro.product_id, oo.uid, 
 rank()over(partition by pro.product_id, oo.uid order by event_time) as rank_times
 from tb_order_detail od
 left join tb_product_info pro using (product_id)
 left join tb_order_overall oo using (order_id)
where pro.tag='零食'
and status=1
and
 datediff(date((select max(event_time) from tb_order_overall)),date(event_time))<90
 )
select 
 product_id,
 round(count(distinct if(rank_times>=2,uid,null))/count(distinct uid),3) as repurchase_rate
 from main
 group by product_id
 order by repurchase_rate desc, product_id
 limit 3




# count(case when rank_times>=2 then 1 else null end)

全部评论

相关推荐

10-01 09:50
门头沟学院 Java
肖先生~:这个人真的很好,点赞
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务