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

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

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
;

三、后记

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

全部评论

相关推荐

05-21 18:32
已编辑
湖南工学院 Java
这条干货多数是给i人朋友们分享的,知道你们开不了口,可以试试我说的这些方法1.调整心态:接受初期的尴尬刚开始进入一个新环境,双方都属于一个认识对方的过程,尴尬瞬间是难免存在的。首先,你要接受尴尬,允许自己犯错,实习期本身就是来学习的,同事也不会期待你完美无缺。另外,不要太以自我为中心,其实你的尴尬瞬间也许没有人在意,是因你的对自己的关注而放大了不安全感。2.准备一些防止尴尬的话题和工作相关的,可以以请教的方式开启。比如:xx,这个表格我没有看懂,可以给我讲一下吗非工作的话题,可以聊聊中午吃什么、当地的天气如何、通勤远不远之类的。比如:附近有什么好吃的外卖吗?我刚来还不太熟悉3.每日练习,逐渐打...
sweep^0416:内向人,遇到好的领导很重要,我之前一段实习组里全e人就我一个i 刚入职第一周还会带着我聊一下,后面越来越冷落我,实在受不了,每天去到就想亖,mentor还要pua说是我融入不了集体(我真的以为是我的问题)后面我离职了,去了现在这一家公司,我的领导也是e人,但是我融入的很好,组里的人全都很好很好,也不会出现小团体什么的,所以说内向不是不融入环境的根本,就是公司跟带教的问题
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务