题解 | #店铺901国庆期间的7日动销率和滞销率#

店铺901国庆期间的7日动销率和滞销率

https://www.nowcoder.com/practice/e7837f66e8fb4b45b694d24ea61f0dc9

with 
    t1 as(
        #筛选出有销售记录的日期
        select 
            distinct
            date(event_time) `dt`
        from tb_order_overall 
        where date_format(event_time,'%Y-%m-%d') between '2021-10-01' and '2021-10-03'
    ),
    t2 as(
        #901商店已经成交的订单,每个下单日期中的product_id
        select
            date(event_time) `dt`,
            tod.product_id
        from tb_order_detail tod
        join tb_order_overall too 
        on tod.order_id=too.order_id and status=1
        join tb_product_info tpi
        on tod.product_id =tpi.product_id and shop_id='901'   
    ),
    t3 as(
        #计算每个日期下901商店的在售商品总数
        select 
            date(event_time) `dt`,
            count(distinct case when datediff(date(event_time),date(release_time))>=0 then product_id end) `sum_product`
        from tb_product_info,tb_order_overall
        where shop_id='901'
        group by dt
    )

    select 
        t1.dt,
        round(count(distinct t2.product_id)/t3.sum_product,3) as sale_rate,
        round(1-count(distinct t2.product_id)/t3.sum_product,3) as unsale_rate
    from t1 
    #关键一步 如果当天存在销量就要输出有结果
    left join t2 
    #也很关键 就是让每个日期都和记录join一下(符合条件)
    on datediff(t1.dt,t2.dt) between 0 and 6
    join t3
    on t1.dt=t3.dt
    group by t1.dt
    order by t1.dt

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
正在热议
更多
# 一张图晒出你司的标语 #
4381次浏览 77人参与
# AI面会问哪些问题? #
28254次浏览 566人参与
# 厦门银行科技岗值不值得投 #
8108次浏览 188人参与
# 你的实习产出是真实的还是包装的? #
20431次浏览 343人参与
# 找AI工作可以去哪些公司? #
9367次浏览 248人参与
# 春招至今,你的战绩如何? #
66293次浏览 585人参与
# 开放七大实习专项,百度暑期实习值得冲吗 #
15399次浏览 223人参与
# 从事AI岗需要掌握哪些技术栈? #
9204次浏览 322人参与
# 中国电信笔试 #
32078次浏览 295人参与
# 你做过最难的笔试是哪家公司 #
34361次浏览 246人参与
# 投递几十家公司,到现在0offer,大家都一样吗 #
340972次浏览 2175人参与
# 哪些公司真双非友好? #
69702次浏览 289人参与
# 阿里笔试 #
179029次浏览 1318人参与
# 机械人避雷的岗位/公司 #
62709次浏览 393人参与
# 小马智行求职进展汇总 #
25140次浏览 80人参与
# 第一份工作一定要去大厂吗 #
14907次浏览 122人参与
# 金三银四,你的春招进行到哪个阶段了? #
22250次浏览 284人参与
# 担心入职之后被发现很菜怎么办 #
291382次浏览 1210人参与
# 为了减少AI幻觉,你注入过哪些设定? #
26283次浏览 310人参与
# 应届生第一份工资要多少合适 #
20694次浏览 86人参与
# HR最不可信的一句话是__ #
6352次浏览 114人参与
# 沪漂/北漂你觉得哪个更苦? #
10045次浏览 194人参与
牛客网
牛客网在线编程
牛客网题解
牛客企业服务