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

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

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

一、题目拆解

1、条件:

周一到周五:weekday(event_time) between 0 and 4

各时段:(case when time(event_time) >='07:00:00' and time(event_time)<'09:00:00' then '早高峰'

when time(event_time) >='09:00:00' and time(event_time)<'17:00:00' then '工作时间'

when time(event_time) >='17:00:00' and time(event_time)<'20:00:00' then '晚高峰'

when time(event_time) >='20:00:00' or time(event_time)<'07:00:00' then '休息时间'

end) as period

2、计算指标:

叫车量:count(period) as get_car_num

平均等待接单时间:先计算timestampdiff(second,event_time,order_time)/60 as wait_time,再计算round(avg(wait_time),1) as avg_wait_time

平均调度时间:先计算timestampdiff(second,order_time,start_time)/60 as dispatch_time,再计算round(avg(dispatch_time),1) as avg_dispatch_time

3、要求

结果按叫车量升序排序:order by get_car_num。

二、题解

with workday as
(select *
from tb_get_car_record
where weekday(event_time) between 0 and 4
),
info as
(select finish_time,(case when time(event_time) >='07:00:00' and time(event_time)<'09:00:00' then '早高峰' 
when time(event_time) >='09:00:00' and time(event_time)<'17:00:00' then '工作时间'
when time(event_time) >='17:00:00' and time(event_time)<'20:00:00' then '晚高峰'
when time(event_time) >='20:00:00' or time(event_time)<'07:00:00' then '休息时间'
end)period,timestampdiff(second,event_time,order_time)/60 wait_time,timestampdiff(second,order_time,start_time)/60 dispatch_time
from (workday left join tb_get_car_order using(order_id))
)

select period,count(*)get_car_num,round(avg(wait_time),1)avg_wait_time,round(avg(dispatch_time),1)avg_dispatch_time
from info
where finish_time is not null
group by period
order by get_car_num
;

三、后记

题目中有一个要求:平均调度时间仅计算完成了的订单,这个我写的题解中并没有考虑这一点,但提交通过了,应该是测试用例没有覆盖到。但话说回来,这个要求要怎么实现,一下子还真没啥思路,欢迎有思路的大佬们来交流~

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-11 11:22
怎么这么多逆天求职者,救救我救救我救救我😭
flmz_Kk:哈哈哈哈哈哈,这么多求职者,肯定有那一两个逆天的
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
今天 17:17
点赞 评论 收藏
分享
真烦好烦真烦:豆包润色了自己没看看吗,再说了,都说豆包是愚蠢且勤快的大学生,ds才是聪明的研究生,怎么敢让豆包写论文的
你们的毕业论文什么进度了
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-08 12:05
俺不中了,BOSS遇到了一个hr,我觉得我咨询的问题都很正常吧,然后直接就被拒绝了???
恶龙战士:你问的太多了,要不就整理成一段话直接问他,一个一个问不太好
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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