题解 | #工作日各时段叫车量、等待接单时间和调度时间#
https://www.nowcoder.com/practice/34f88f6d6dc549f6bc732eb2128aa338
# 各时段左闭右开: # CASE WHEN 7 <= HOUR(event_time) < 9 THEN END period # 叫车量: COUNT(event_time) # 等待接单时间: 响应时间 end_time - event_time # 调度时间:start_time - order_time # 周一到周五? >> DAYOFWEEK() BETWEEN 2 AND 6 周日是1 # 平均调度时间仅计算完成了的订单? SELECT CASE WHEN HOUR(event_time) BETWEEN 7 AND 8 THEN "早高峰" WHEN HOUR(event_time) BETWEEN 9 AND 16 THEN "工作时间" WHEN HOUR(event_time) BETWEEN 17 AND 19 THEN "晚高峰" ELSE "休息时间" END period ,COUNT(event_time) get_car_num ,ROUND(AVG(TIMESTAMPDIFF(SECOND,event_time,end_time))/60,1) avg_wait_time # 直接minute只保留整数 ,ROUND(AVG(TIMESTAMPDIFF(SECOND,order_time,start_time))/60,1) avg_dispatch_time FROM tb_get_car_record a JOIN tb_get_car_order b ON a.order_id = b.order_id WHERE DAYOFWEEK(event_time) BETWEEN 2 AND 6 GROUP BY CASE WHEN HOUR(event_time) BETWEEN 7 AND 8 THEN "早高峰" WHEN HOUR(event_time) BETWEEN 9 AND 16 THEN "工作时间" WHEN HOUR(event_time) BETWEEN 17 AND 19 THEN "晚高峰" ELSE "休息时间" END ORDER BY get_car_num