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

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

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

#问题:统计周一到周五各时段的叫车量、平均等待接单时间和平均调度时间。全部以event_time-开始打车时间为时段划分依据,平均等待接单时间和平均调度时间均保留1位小数,平均调度时间仅计算完成了的订单,结果按叫车量升序排序。

/*

不同时段定义:早高峰 [07:00:00 , 09:00:00)、工作时间 [09:00:00 , 17:00:00)、晚高峰 [17:00:00 , 20:00:00)、休息时间 [20:00:00 , 07:00:00)

1.周一到周五 时间段

2.平均等待时间 调度时间

仅计算完成订单

*/

select (case when hour(event_time) Between 7 and 8 then '早高峰'

       when hour(event_time) Between 9 and 16 then '工作时间'

       when hour(event_time) Between 17 and 19 then '晚高峰'

       else '休息时间' end )period,

       count(order_id) get_car_num,

       round(avg(timestampdiff(second,event_time,order_time)/60),1) avg_wait_time,

       round(avg(timestampdiff(second,order_time,start_time)/60),1) avg_dispatch_time

from tb_get_car_record

join tb_get_car_order using(order_id)

where order_id is not null and finish_time is not null and DayOfWeek(event_time) between 2 and 6

group by period

order by get_car_num

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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