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

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

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

select o7.date_time,o7.sale_rate,o7.unsale_rate from (
select distinct DATE_FORMAT(o5.event_time,'%Y-%m-%d')  as event_time from 
                            tb_order_overall as o5 ) o6 
 inner join (
select a2.date_time,round(a2.cnt/a2.cnt_all,3) as sale_rate, 
round(1-a2.cnt/a2.cnt_all,3) as unsale_rate  from 
(select * 
 from 
(
#获取2021-10-01销售的产品数量
select '2021-10-01' as date_time,count(distinct t1.product_id) as cnt,
(select count(*) as cnt_all from tb_product_info as p2 where p2.shop_id='901') as cnt_all
from (
select o1.order_id,o1.product_id,o2.event_time from tb_order_detail as o1 inner join 
tb_order_overall as o2 on o1.order_id=o2.order_id 
where DATEDIFF('2021-10-01',o2.event_time)<7 and DATEDIFF('2021-10-01',o2.event_time)>=0 
and o1.product_id in 
(select p1.product_id from tb_product_info as p1 where p1.shop_id='901')) t1) a1 
union 
# 获取2021-10-02销售的产品数量
select '2021-10-02' as date_time,count(distinct t2.product_id) as cnt,
(select count(*) as cnt_all from tb_product_info as p2 where p2.shop_id='901') as cnt_all
from (
select o1.order_id,o1.product_id,o2.event_time from tb_order_detail as o1 inner join 
tb_order_overall as o2 on o1.order_id=o2.order_id 
where DATEDIFF('2021-10-02',o2.event_time)<7 and DATEDIFF('2021-10-02',o2.event_time)>=0 
and o1.product_id in 
(select p1.product_id from tb_product_info as p1 where p1.shop_id='901')) t2 
union 

# 获取2021-10-03销售的产品数量
select '2021-10-03' as date_time,count(distinct t3.product_id) as cnt,
(select count(*) as cnt_all from tb_product_info as p2 where p2.shop_id='901') as cnt_all
from (
select o1.order_id,o1.product_id,o2.event_time from tb_order_detail as o1 inner join 
tb_order_overall as o2 on o1.order_id=o2.order_id 
where DATEDIFF('2021-10-03',o2.event_time)<7 and DATEDIFF('2021-10-03',o2.event_time)>=0 
and o1.product_id in 
(select p1.product_id from tb_product_info as p1 where p1.shop_id='901')) t3 ) 
    a2   ) o7 on o6.event_time=o7.date_time
全部评论
好像 没有判断已上架的商品
点赞 回复 分享
发布于 2022-01-29 14:35

相关推荐

我就是0offer糕手:北大不乱杀
点赞 评论 收藏
分享
Cherrycola01:0实习 0项目 约等于啥也没有啊 哥们儿这简历认真的吗
点赞 评论 收藏
分享
05-28 23:26
河南大学 Java
双非本,刚学完Redis,项目只有外卖和点评,八股没准备,算法只有lqb省一,感觉敲的项目也是一言难尽没怎么吸收。怎么你们都有实习了
大牛之途:27急个锤子,你投日常实习最好的时间就是9,10月份,那时候暑期实习都结束了,正是缺人的时候。这份日常又能给你的暑期实习增加竞争力,暑期找的好了秋招也不怕了,都是环环相扣的
点赞 评论 收藏
分享
评论
7
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务