题解 | #零食类商品中复购率top3高的商品(时间筛选)#

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

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

select product_id,round(sum(if(c>=2,1,0))/count(*),3) repurchase_rate
from (
select distinct tb_order_detail.product_id ,uid,
count(*) over(partition by tb_order_detail.product_id,uid ) c
from tb_order_detail  
join tb_product_info on tb_product_info.product_id = tb_order_detail.product_id 
join tb_order_overall on tb_order_overall.order_id = tb_order_detail.order_id
where datediff((select max(date(event_time)) from tb_order_overall),date(event_time)) < 90 and 
tag = '零食') t1
group by product_id
order by repurchase_rate desc,product_id 
limit 3

时间范围:

1 datediff((select max(date(event_time)) from tb_order_overall),date(event_time)) < 90

2 event_time >= (SELECT DATE_SUB(MAX(event_time), INTERVAL 89DAY) FROM tb_order_overall

思路:三表链接选取90天内标签为零食的数据,计算每个产品被每个uid购买的次数(窗口函数),根据商品分组计算购买商品的总uid数和购买2次及以上的次数

全部评论

相关推荐

苍蓝星上艾露:这简历。。。可以试试我写的开源简历优化工具https://github.com/weicanie/prisma-ai
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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