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

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

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

with a as(
    select t1.order_id,t1.product_id, t2.uid
    from tb_order_detail t1
    left join tb_order_overall t2 on t1.order_id=t2.order_id
    left join tb_product_info t3 on t1.product_id=t3.product_id
    where 
        datediff((select max(event_time) from tb_order_overall),event_time) <= 89
        and tag='零食'
)

select 
    t1.product_id, 
    round(count(distinct uid)/total_cnt,3) as repurchase_rate
from(
-- total_cnt
    select 
        product_id,
        count(distinct uid) as total_cnt
    from a
    group by product_id
) t1
left join (
-- repur
    select 
        product_id,
        uid
    from a
    group by product_id, uid
    having count(uid) >= 2
) t2
on t1.product_id=t2.product_id
group by t1.product_id,total_cnt
order by repurchase_rate desc
limit 3

全部评论

相关推荐

06-15 18:44
黄淮学院 Java
Lynn012:如果是居民楼还是算了吧,看着有点野呢
点赞 评论 收藏
分享
05-19 19:57
蚌埠学院 Python
2237:Gpa70不算高,建议只写排名,个人技能不在多而在精,缩到8条以内。项目留一个含金量高的,减少间距弄到一页,硕士简历也就一页,本科不要写很多
实习,投递多份简历没人回...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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