题解 | #国庆期间近7日日均取消订单量#

国庆期间近7日日均取消订单量

https://www.nowcoder.com/practice/2b330aa6cc994ec2a988704a078a0703

with dt_num as
(
select substr(order_time,1,10) as dt
,sum(case when start_time is null then 1 else 0 end) as cancel_num
,sum(case when start_time is not null then 1 else 0 end) as finish_num
from tb_get_car_order
group by substr(order_time,1,10)
)

select dt
,round(sum(finish_num)/count(before_dt),2) as finish_num_7d
,round(sum(cancel_num)/count(before_dt),2) as cancel_num_7d
from
(
    select a.dt as dt
    ,b.dt as before_dt
    ,b.cancel_num
    ,b.finish_num
    ,rank() over(partition by a.dt order by b.dt desc) as rk
    from dt_num a
    left join dt_num as b
    on b.dt<= a.dt 
)t
where rk>=1 and rk<=7
and dt>='2021-10-01' and dt <='2021-10-03'
group by dt

全部评论

相关推荐

11-03 14:38
重庆大学 Java
AAA求offer教程:我手都抬起来了又揣裤兜了
点赞 评论 收藏
分享
11-11 14:21
西京学院 C++
Java抽象练习生:教育背景放最前面,不要耍小聪明
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务