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

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

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

with a as (select  sum(case when start_time is not null then 1 else 0 end) finish_day,
        sum(case when start_time is null then 1 else 0 end) cancel_day,
        date(order_time) as dt
from tb_get_car_order
where DATE(order_time) BETWEEN '2021-09-25' AND '2021-10-03'
group by date(order_time))

select  dt,
        round(sum(finish_day)over(order by dt rows between  6 preceding and current row)/7,2),
        round(sum(cancel_day)over(order by dt rows between  6 preceding and current row)/7,2)
from a 
limit 6, 3

步骤一:计算每天完成与取消的订单,通过date() between 形成每日的订单序列

步骤二:利用over(rows between)锁定当前行并向前提取六行,sum求和,取10-01到10-03

全部评论

相关推荐

点赞 评论 收藏
分享
不知道怎么取名字_:愚人节收到的吧,刚看到有人也是愚人节说收到offer的
腾讯求职进展汇总
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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