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

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

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

# 3.13  11:00- 11:40

# 字段:period、get_car_num、avg_wait_time、avg_dispatch_time
# 时间:周一到周五  

# 平均等待时间
# tb11:链接
with tb1 as(
    select order_id,
    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 
        as period,
    event_time,
    timestampdiff(second,event_time,end_time) as wait_time,
    timestampdiff(second,order_time,start_time) as dispatch_time
    from tb_get_car_order left join tb_get_car_record using(order_id)
    where weekday(event_time) between 0 and 4  # 星期数公式?
    # AND fare is not null
)

# tb2:不同时间段,count car,
select period,count(order_id) as get_car_num,
round(avg(wait_time)/60,1) as  avg_wait_time,
round(avg(dispatch_time)/60,1) as avg_dispatch_time
from tb1
group by period
order by count(order_id) asc

# 星期数公式
# weekday:0到6代表星期一到星期日
# dayofweek:从1到7代表星期日到星期六


# 注意点:需要排除未完成的订单
# 但是这题不排除fare为空的反而正确的?

全部评论

相关推荐

02-14 12:40
门头沟学院 Java
程序员花海:1.面试要求必须Java笔试不一定 2.难度对等秋招 远超于日常实习是因为同一批次且转正很多 竞争压力大 3.第一个加点指标,上线了就把接口性能加上去 使用本地缓存这个不算亮点 只是技术选型,要把为什么采用这个和背后的思考写出来而不是单纯堆叠技术没意义 4.八股要一直看 很容易忘记 5.拼团交易这个老问题 堆积技术 另外建议你把奖项合并到教育背景 没必要拆出来放最后
我的简历长这样
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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