题解|TIME函数 工作日写法| 叫车量、等待接单和调度时间

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

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

## 等待时间:接单时间-打车时间 order_time - event_time
## 调度时间:上车时间-接单时间 start_time = order_time
## 打车数量:COUNT(order_id) AS get_car_num
SELECT
    (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 '晚高峰'
    ELSE '休息时间' END) AS period,
    COUNT(order_id) AS get_car_num,
    ROUND(AVG(TIMESTAMPDIFF(SECOND,event_time,order_time))/60,1) AS avg_wait_time,
    ROUND(AVG(TIMESTAMPDIFF(SECOND,order_time,start_time))/60,1) AS avg_dispatch_time
FROM tb_get_car_order
JOIN tb_get_car_record
USING (order_id)
WHERE WEEKDAY(event_time) BETWEEN 0 AND 4
GROUP BY period
ORDER BY get_car_num

全部评论

相关推荐

10-11 17:45
门头沟学院 Java
走吗:别怕 我以前也是这么认为 虽然一面就挂 但是颇有收获!
点赞 评论 收藏
分享
10-30 10:16
南京大学 Java
龚至诚:给南大✌️跪了
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务