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

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

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
;

三、后记

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

全部评论

相关推荐

神哥不得了:神哥来啦~自我评价和校园经历的话可以直接删了,从大厂暑期的话应该没有什么太多问题,应该是能拿到很多大厂面试机会的,就是在面试的时候表示的好一点就行,可以在面试前先把高频top 50的八股多巩固几遍,千万不要看那些假高频八股,这两个项目的话问题不是很大,应该能够帮你找到大厂实习的,算法的话一定要刷起来,因为大厂有些还是比较看重算法的
点赞 评论 收藏
分享
03-02 16:31
已编辑
合肥工业大学 golang
程序员鼠鼠_春招版:学历可以,项目普通,评价多余,奖项没有,如果有面试都是因为学历给你的,我建议可以随便包几个奖项上去,像什么蓝桥杯天梯赛,虽然不一定有用,但是相比acm这种风险小多了,我几段实习下来,压根没查的,第二点是包一段小厂实习,大厂你不好拿捏,小厂打打杂也能让你在26里面出彩一点
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务