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

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

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

with t1 as(
select t1.product_id,date(t3.event_time) as dt,
(select count(distinct product_id) from tb_product_info ledt join tb_order_detail 
using(product_id) where shop_id=901) as total  from tb_product_info t1 
join tb_order_detail t2 
on t1.product_id=t2.product_id
join tb_order_overall t3 
on t2.order_id=t3.order_id
where shop_id=901),

t2 as(select date(event_time) dt from tb_order_overall where date(event_time) between '2021-10-01' AND '2021-10-03'),

t3 as(
select distinct t2.dt,t1.product_id,t1.total
from t2 left join t1 on 
datediff(t2.dt,t1.dt) between 0 and 6
order by t2.dt)

select dt,
IFNULL(round(count(distinct product_id)/total,3),0) as sale_rate,
ifnull(round(1-count(distinct product_id)/total,3),1) as unsale_rate
from t3 group by dt


全部评论

相关推荐

07-01 13:37
门头沟学院 Java
steelhead:不是你的问题,这是社会的问题。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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