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

全部评论

相关推荐

04-30 21:35
已编辑
长安大学 C++
晓沐咕咕咕:评论区没被女朋友好好对待过的计小将可真多。觉得可惜可以理解,毕竟一线大厂sp。但是骂楼主糊涂的大可不必,说什么会被社会毒打更是丢人。女朋友体制内生活有保障,读研女朋友还供着,都准备订婚了人家两情相悦,二线本地以后两口子日子美滋滋,哪轮到你一个一线城市房子都买不起的996清高计小将在这说人家傻😅
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

更多
牛客网
牛客企业服务