题解 | #工作日各时段叫车量、等待接单时间和调度时间#

工作日各时段叫车量、等待接单时间和调度时间

https://www.nowcoder.com/practice/34f88f6d6dc549f6bc732eb2128aa338

select 
    period,
    count(get_car) as get_car_num,
    round(avg(wait_time/60),1) as avg_wait_time,
    round(avg(dispatch_time/60),1) as avg_dispatch_time
from
(
select 
    o.order_id as get_car,
    case 
    when hour(event_time) >=7 and hour(event_time) < 9 then '早高峰'
    when hour(event_time) >=9 and hour(event_time) < 17 then '工作时间'
    when hour(event_time) >=17 and hour(event_time) < 20 then '晚高峰'
    else '休息时间' end as period,
    timestampdiff(second,event_time,order_time) as wait_time,
    timestampdiff(second,order_time,start_time) as dispatch_time
from 
    tb_get_car_record r  left join tb_get_car_order o using(order_id)
where 
    weekday(event_time) between 0 and 4
) t1
group by 
    period
order by 
    count(get_car)

timestampdiff(minute,event_time,order_time)会对结果直接取整,如果是1.4分钟,也四舍五入为1分钟了,所以先计算秒

全部评论
题目要求“平均调度时间仅计算完成了的订单”,相关过滤条件是忘写了吗
点赞 回复 分享
发布于 2023-06-30 14:42 湖北

相关推荐

码农索隆:单休一个月少休息4天,一年就是48天,平时节假日,别人3天假期,单休的两天
点赞 评论 收藏
分享
06-26 15:33
青岛工学院 Java
积极的秋田犬要冲国企:他现在邀请我明天面试
点赞 评论 收藏
分享
06-12 16:23
已编辑
小米_软件开发(准入职员工)
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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