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

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

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

with t1 as (
select (select date(max(event_time)) from tb_order_overall tl) as current_t,
date(event_time) as event_time,
ti.product_id,
td.order_id,
uid
from tb_product_info ti
left join tb_order_detail td on ti.product_id = td.product_id
left join tb_order_overall tl on td.order_id = tl.order_id
where tag='零食'
and status = 1
)
select product_id,
round(count(distinct case when num>=2 then uid else null end )/count(distinct uid),3) as repurchase_rate
from(
select product_id,
uid,
count(order_id) as num
from t1
where datediff(current_t,event_time)<90
group by product_id,
uid
)a 
group by  product_id
order by repurchase_rate desc , product_id
limit 3



全部评论

相关推荐

不愿透露姓名的神秘牛友
08-15 16:48
想要一个AK:问题很多加微信私聊 (一个赞十道算法题,我看看有多少)
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务