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

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

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

with
    combineday as (
        select
            '2021-10-01' as date
        union
        select
            '2021-10-02'
        union
        select
            '2021-10-03'
    ),
    dataList as (
        select
            tb_get_car_record.uid,
            order_id,
            start_time,
            finish_time
        from
            tb_get_car_record
            join tb_get_car_order using (order_id)
    )
select
    date,
    round(count(start_time)/7,2),#已完成的订单总量
    round(sum(if(start_time is null ,1 ,0))/7,2)#取消订单量
from
    combineday,
    dataList
where
    datediff (date, date(finish_time)) between 0 and 6
group by date

本题解法一:

先定义一个临时表,内含10-1,10-2, 10-3,与组合表进行一个连接,只要判断finish_time在国庆前三日的时间差为0-6即可,

根据国庆前三日进行聚合,得出总计的订单量和总计的取消量除以7即可。

全部评论

相关推荐

10-14 21:00
门头沟学院 Java
吃花椒的狸猫:这个人说的倒是实话,特别是小公司,一个实习生哪里来的那么多要求
点赞 评论 收藏
分享
明天不下雨了:这个项目 这个简历 这个模板 莫不是一个开源的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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