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

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

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

select *
from(
select '2021-10-01' as "dt", round(count(1)/(
                select count(1)  # 截止到10-01,在售商品数
                from tb_product_info
                where date(release_time) <= '2021-10-01'
                and shop_id = 901
                ),3) as "sale_rate", (1-round(count(1)/( 
                select count(1)  # 截止到10-01,在售商品数
                from tb_product_info
                where date(release_time) <= '2021-10-01'
                and shop_id = 901
                ),3)) as "unsale_rate"
from(
select count(1),tod.product_id
from tb_order_overall too join tb_order_detail tod
on too.order_id = tod.order_id
join tb_product_info tpi
on tod.product_id = tpi.product_id
where event_time between '2021-09-25' and '2021-10-02'
and status = 1
and total_cnt > 0
and tpi.shop_id = 901
group by tod.product_id
)t1
union all
select '2021-10-02' as "dt", round(count(1)/(
                select count(1)  # 截止到10-01,在售商品数
                from tb_product_info
                where date(release_time) <= '2021-10-02'
                and shop_id = 901
                ),3) as "sale_rate", (1-round(count(1)/( 
                select count(1)  # 截止到10-01,在售商品数
                from tb_product_info
                where date(release_time) <= '2021-10-02'
                and shop_id = 901
                ),3)) as "unsale_rate"
from(
select count(1),tod.product_id
from tb_order_overall too join tb_order_detail tod
on too.order_id = tod.order_id
join tb_product_info tpi
on tod.product_id = tpi.product_id
where event_time between '2021-09-26' and '2021-10-03'
and status = 1
and total_cnt > 0
and tpi.shop_id = 901
group by tod.product_id
)t2
union all
select '2021-10-03' as "dt", round(count(1)/(
                select count(1)  # 截止到10-01,在售商品数
                from tb_product_info
                where date(release_time) <= '2021-10-03'
                and shop_id = 901
                ),3) as "sale_rate", (1-round(count(1)/( 
                select count(1)  # 截止到10-01,在售商品数
                from tb_product_info
                where date(release_time) <= '2021-10-03'
                and shop_id = 901
                ),3)) as "unsale_rate"
from(
select count(1),tod.product_id
from tb_order_overall too join tb_order_detail tod
on too.order_id = tod.order_id
join tb_product_info tpi
on tod.product_id = tpi.product_id
where event_time between '2021-09-27' and '2021-10-04'
and status = 1
and total_cnt > 0
and tpi.shop_id = 901
group by tod.product_id
)t3
)final_t
where dt in (
    select date(event_time)
    from tb_order_overall
)
order by dt 


# select count(1), tod.product_id
# from tb_order_overall too join tb_order_detail tod
# on too.order_id = tod.order_id
# join tb_product_info tpi
# on tod.product_id = tpi.product_id
# where event_time between '2021-09-26' and '2021-10-04'
# and status = 1
# and total_cnt > 0
# and tpi.shop_id = 901
# group by tod.product_id

全部评论

相关推荐

程序员猪皮:看不到八股什么意思
点赞 评论 收藏
分享
微风不断:兄弟,你把四旋翼都做出来了那个挺难的吧
点赞 评论 收藏
分享
点赞 1 评论
分享
牛客网
牛客企业服务