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

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

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

不得不说最坑的点就是那一句,理解了就简单了

  • ”只要当天任一店铺有任何商品的销量就输出该天的结果,即使店铺901当天的动销率为0“
with dts  as( -- 2021国庆头三天 有销量的日期
select distinct 
    date(event_time) dt
from tb_order_overall 
where date(event_time) between '2021-10-01' and '2021-10-03'
),
 sale as (	 -- 901 店铺 每天销售的商品
 select distinct
     date(a.event_time) dt 
     ,b.product_id
 from tb_order_overall a 
 inner join tb_order_detail b
    on a.order_id = b.order_id
 inner join tb_product_info c
    on b.product_id = c.product_id
 where date(a.event_time) between '2021-09-25'  and '2021-10-03'
     and c.shop_id=901
 ),
 total as (-- 901 店铺 每天上线的商品
  select date(release_time) rel_dt
        ,product_id
  from tb_product_info
  where shop_id=901
 )
 -- 做笛卡尔积 判断时间差即可
 select 
    a.dt
    ,round(count(distinct if(datediff(a.dt,b.dt) between 0 and 6,b.product_id,null))
    /count(distinct if(c.rel_dt <=a.dt,c.product_id,null)),3) as sale_rate
    ,1-round(count(distinct if(datediff(a.dt,b.dt) between 0 and 6,b.product_id,null))
    /count(distinct if(c.rel_dt <=a.dt,c.product_id,null)),3) as unsale_rate
 from dts a
 join sale b
 join total c
 group by 1
 order by 1 
 
全部评论

相关推荐

07-15 14:14
门头沟学院 Java
7.10投递7.15感谢信
投递地平线等公司8个岗位
点赞 评论 收藏
分享
06-10 21:15
门头沟学院 Java
宁阿:好多这种没🧠的公司,他们估计都不知道毕业的人不能给安排实习岗
实习吐槽大会
点赞 评论 收藏
分享
06-18 08:36
湖南大学 Java
运营你豪哥:没啥拷打的 1.增加量化结果,现在有点缺效果数据 2.突出复杂性,现在的项目描述有点像功能清单,强调一下技术难点和解决方案。
不给转正的实习,你还去吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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