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

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

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

with t as (
  select
    a.product_id,
    event_time,
    release_time,
    shop_id
  from
    tb_order_detail a
    left join tb_order_overall b on a.order_id = b.order_id
    left join tb_product_info c on a.product_id = c.product_id
  where
    status = 1
)
select
  dt,
  round(sale_cnt / total_cnt, 3) as sale_rate,
  round(1 - sale_cnt / total_cnt, 3) as unsale_rate
from
  (
    select
      t1.dt,
      count(distinct t2.product_id) as sale_cnt,
      count(distinct t3.product_id) as total_cnt
    from
      (
        select
          distinct date(event_time) dt
        from
          t
      ) t1
      left join (
        select
          product_id,
          date(event_time) dt
        from
          t
        where
          shop_id = 901
      ) t2 on datediff(t1.dt, t2.dt) between 0 and 6
      left join(
        select
          product_id,
          date(release_time) as release_dt
        from
          t
        where
          shop_id = 901
      ) t3 on t3.release_dt < t1.dt
    group by
      t1.dt
  ) tt
  where dt between '2021-10-01' and '2021-10-03'
  order by dt
全部评论
按时间连接,如果连上了就是符合条件的
点赞 回复 分享
发布于 2022-12-25 22:14 江苏

相关推荐

10-24 11:10
山西大学 Java
若梦难了:哥们,面试挂是很正常的。我大中厂终面挂,加起来快10次了,继续努力吧。
点赞 评论 收藏
分享
牛客279957775号:铁暗恋
点赞 评论 收藏
分享
1 收藏 评论
分享
牛客网
牛客企业服务