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

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

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

select  product_id,round(sum(case when num >=2 then 1 else 0 end)/count(*),3) as repurchase_rate from (
select product_id,uid,count(*) as num
from tb_order_overall join tb_order_detail using(order_id)
join tb_product_info using(product_id)
where datediff((select max(date(event_time)) from tb_order_overall),date(event_time)) <90
and tag = '零食'
group by product_id,uid)t
group by product_id
order by repurchase_rate desc,product_id 
limit 3

嵌套from子查询

先算出每个产品,每个人购买过多少次,然后再计算复购率

全部评论

相关推荐

11-01 08:48
门头沟学院 C++
伤心的候选人在吵架:佬你不要的,能不能拿户口本证明过户给我。。球球了
点赞 评论 收藏
分享
1 1 评论
分享
牛客网
牛客企业服务