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

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

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

select period
,count(order_id) as get_cat_num
,round(avg(wait_time),1) as avg_wait_time
,round(sum(dispatch_time)/sum(if_finish),1) as avg_dispatch_time
from (
select date(event_time)
,substr(event_time,12,2)
,event_time,order_time,start_time
,re.order_id as order_id
,case when substr(event_time,12,2) >=7 and substr(event_time,12,2) <9 then '早高峰'
    when substr(event_time,12,2) >=9 and substr(event_time,12,2)<17 then '工作时间'
    when substr(event_time,12,2) >=17 and substr(event_time,12,2)<20 then '晚高峰'
    else '休息时间' end as period
,timestampdiff(second,event_time,order_time)/60 as wait_time
# ,timestampdiff(minute,event_time,order_time) as wait_time1 
#时间参数只保留整数位,故需要秒进行转换
,timestampdiff(second,order_time,start_time)/60 as dispatch_time  
,if(mileage>0,1,0) as if_finish
from tb_get_car_record re
left join tb_get_car_order ord on re.order_id=ord.order_id
where weekday(event_time)  between 0 and 4 
) a 
group by period
order by get_cat_num

解题思路:

1.先构建中间表,进行表关联后进行数据过滤,用where过滤为周一到周五,用weekday()函数;

2.统计中间表字段,叫车单号/时段/时段分类/每单的等待时间差/每单的调度时间差,注意到秒到维度后,在处理为以分钟为单位,时间差函数timestampdiff(second,,)/60 ;

3.添加是否完成订单字段if_finish,用于计算平均调度时间

4.以时段分组period,聚合统计时段叫车量/平均等待时间/平均调度时间

5.输出结果小数位数处理round(),并按叫车量升序排序

知识点补充:

1.日期进行时间切割,取出时段

2.日期进行星期的处理判断.WEEKDAY函数接受1个参数,即DATE或DATETIME值,它返回一个整数,范围从0到6,表示星期一到星期日。

3.时间差计算。timestampdiff()函数的熟练使用

timestampdiff(minute,event_time,order_time) as wait_time1

#时间参数只保留整数位,故需要秒进行转换

全部评论

相关推荐

06-15 02:05
已编辑
南昌航空大学 数据分析师
Eason三木:你如果想干技术岗,那几个发公众号合唱比赛的经历就去掉,优秀团员去掉,求职没用。然后CET4这种不是奖项,是技能,放到下面的专业技能里或者单独列一个英语能力。 另外好好改改你的排版,首行缩进完全没有必要,行间距好好调调,别让字和标题背景黏在一起,你下面说能做高质量PPT你得展现出来啊,你这简历排版我用PPT做的都能比你做的好。 然后自我评价,你如果要干数据工程师,抗压能力强最起码得有吧。
简历中的项目经历要怎么写
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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