题解 | #有取消订单记录的司机平均评分#
有取消订单记录的司机平均评分
http://www.nowcoder.com/practice/f022c9ec81044d4bb7e0711ab794531a
前滴滴数据分析前来mark~
# 只看一句话,判断“取消”:“若乘客上车前,乘客或司机点击取消订单, # 会将打车订单表对应订单的finish_time-订单完成时间填充为取消时间,其余字段设为null。” # 即其余字端有null时,订单为取消状态;取出这时的driver_id SELECT * FROM ( SELECT driver_id, ROUND(AVG(grade),1) avg_grade FROM tb_get_car_order WHERE driver_id IN (SELECT driver_id FROM tb_get_car_order WHERE start_time IS NULL AND DATE_FORMAT(order_time,"%Y%m") = "202110") GROUP BY driver_id ORDER BY driver_id) a # 因为有order by,需要多一层;order by执行顺序在union之后 UNION SELECT "总体" AS driver_id, ROUND(AVG(grade),1) avg_grade FROM tb_get_car_order WHERE driver_id IN (SELECT driver_id FROM tb_get_car_order WHERE start_time IS NULL AND DATE_FORMAT(order_time,"%Y%m") = "202110")