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

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

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

select aperiod,count(order_id) get_car_num,round(sum(wait_time)/(count(order_id) *60),1) avg_wait_time,/*单位是分每单*/
round(sum(dispatch_time)/(count(start_time)*60),1) avg_dispatch_time 
from
(select tgo.order_id,event_time,order_time,start_time,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  aperiod,
timestampdiff(second,event_time,order_time) wait_time, /*等待时间*/
if(start_time is not null,timestampdiff(second,order_time,start_time),0) dispatch_time /*调度时间.如取消订单,则不计算*/
from tb_get_car_order tgo
join tb_get_car_record tgc on tgc.order_id=tgo.order_id
where dayofweek(event_time) between 2 and 6) zb
group by aperiod
order by get_car_num

全部评论

相关推荐

季桑陌:这怎么看是不是外包啊
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
03-18 14:29
牛客604067584号:感觉算法卷的人少很多,毕竟只有一部分bg还不错的硕士才会考虑算法,虽然hc不如后端,但是竞争真的少很多。
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务