题解 | #店铺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-15 16:27
门头沟学院 C++
LeoMoon:建议问一下是不是你给他付钱😅😅
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
11-21 17:16
科大讯飞 算法工程师 28.0k*14.0, 百分之三十是绩效,惯例只发0.9
点赞 评论 收藏
分享
1 收藏 评论
分享
牛客网
牛客企业服务