题解|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

全部评论

相关推荐

牛客101244697号:这个衣服和发型不去投偶像练习生?
点赞 评论 收藏
分享
totoroyyw:千年老妖😂
投递华为等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务