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

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

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

屎山代码,但是思路最简单的了,核心语句就一条,来回切换时间

with t as ( select product_id,event_time

    from tb_product_info

    join tb_order_detail using(product_id)

    join tb_order_overall using(order_id)

    where shop_id='901'

    and status=1   )

select dt, round(sale_rate,3) sale_rate,round(1-sale_rate,3) unsale_rate

from (

select '2021-10-01' dt

    ,count(distinct product_id)/(select count(product_id) from tb_product_info where date(release_time)<='2021-10-01')  sale_rate

from t

where datediff('2021-10-01',event_time) between 0 and 6

union

select '2021-10-02' dt

    ,count(distinct product_id)/(select count(product_id) from tb_product_info where date(release_time)<='2021-10-02')

from t

where datediff('2021-10-02',event_time) between 0 and 6

union

select '2021-10-03' dt

    ,count(distinct product_id)/(select count(product_id) from tb_product_info where date(release_time)<='2021-10-03')

from t

where datediff('2021-10-03',event_time) between 0 and 6   ) total_tab

全部评论

相关推荐

昨天 17:54
门头沟学院 营销
点赞 评论 收藏
分享
点赞 评论 收藏
分享
牛客37328580...:个人感觉项目只是列出来了
点赞 评论 收藏
分享
投递OPPO等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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