题解 | #店铺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

全部评论

相关推荐

肥沃富饶:可能初创公司,老板不懂技术
点赞 评论 收藏
分享
01-24 08:13
已编辑
合肥工业大学 Java
程序员牛肉:没啥问题。标准的流水线简历,但是学历好一点,所以应该是有约面的机会的。 这段时间可以考虑把自己的两个项目彻底的理一理。争取能够讲清楚每一个功能点
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

更多
牛客网
牛客企业服务