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

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

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

with t1 as (select a.product_id,event_time,(select count(1) from tb_product_info where shop_id = 901) total_num
from tb_product_info a 
left join tb_order_detail b 
on a.product_id = b.product_id
left join tb_order_overall c 
on b.order_id = c.order_id
where shop_id = 901
and status = 1
)



select dt,sale_rate,unsale_rate from (select '2021-10-01' dt,round(count(distinct case when date(event_time) between '2021-09-25' and '2021-10-01' then product_id else null end)/total_num,3) sale_rate,
round(1-count(distinct case when date(event_time) between '2021-09-25' and '2021-10-01' then product_id else null end)/total_num,3) unsale_rate,
(select count(1) from tb_order_overall where date(event_time) = '2021-10-01') yes_or_no
from t1
union 
select '2021-10-02' dt,round(count(distinct case when date(event_time) between '2021-09-26' and '2021-10-02' then product_id else null end)/total_num,3) sale_rate,
round(1-count(distinct case when date(event_time) between '2021-09-26' and '2021-10-02' then product_id else null end)/total_num,3) unsale_rate,
(select count(1) from tb_order_overall where date(event_time) = '2021-10-02') yes_or_no from t1
union
select '2021-10-03' dt,round(count(distinct case when date(event_time) between '2021-09-27' and '2021-10-03' then product_id else null end)/total_num,3) sale_rate,
round(1-count(distinct case when date(event_time) between '2021-09-27' and '2021-10-03' then product_id else null end)/total_num,3) unsale_rate,
(select count(1) from tb_order_overall where date(event_time) = '2021-10-03') yes_or_no from t1) u
where yes_or_no != 0

全部评论

相关推荐

jack_miller:我给我们导员说我不在这里转正,可能没三方签了。导员说没事学校催的时候帮我想办法应付一下
点赞 评论 收藏
分享
牛舌:如果我不想去,不管对方给了多少,我一般都会说你们给得太低了。这样他们就会给下一个offer的人更高的薪资了。
点赞 评论 收藏
分享
字节 飞书绩效团队 (n+2) * 15 + 1k * 12 + 1w
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务