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

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

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

写的很差,暴力解出来的,注意1819行的窗口函数吧



select 
total_num.product_id,
round(count(two_num.uid)/total_num.uid,3) repurchase_rate
from
(
select 
a.product_id,
count(distinct a.uid) uid
from
(
select
tod.product_id,
too.uid,
if(datediff(max(too.event_time) over(),
too.event_time)<=89,1,0) ninteen_day
from
tb_order_detail tod left join tb_order_overall too
on tod.order_id=too.order_id
) a
where a.ninteen_day=1
group by a.product_id
) total_num
left join 
(
select 
a.product_id,
a.uid,
count(a.event_time)
from
(
select
tod.product_id,
too.uid,
too.event_time,
if(datediff(max(too.event_time) over(),
too.event_time)<=89,1,0) ninteen_day
from
tb_order_detail tod left join tb_order_overall too
on tod.order_id=too.order_id
) a
where a.ninteen_day=1
group by a.product_id,a.uid
having count(a.event_time)>=2
) two_num
on total_num.product_id=two_num.product_id
left join tb_product_info on total_num.product_id=tb_product_info.product_id
where tb_product_info.tag='零食'
group by total_num.product_id
order by repurchase_rate desc,total_num.product_id
limit 3

全部评论

相关推荐

10-14 10:56
已编辑
长沙学院 嵌入式软件开发
痴心的00后拿到了ssp:hr面挂了,无所谓了反正不去😃
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
昨天 18:54
点赞 评论 收藏
分享
点赞 1 评论
分享
牛客网
牛客企业服务