题解 | #有取消订单记录的司机平均评分#
有取消订单记录的司机平均评分
https://www.nowcoder.com/practice/f022c9ec81044d4bb7e0711ab794531a
#小白好理解的写法 with tiaojian as ( select driver_id from tb_get_car_order //求出有取消记录的司机 where start_time is null and date_format(order_time,"%Y%m")=202110 ) select ifnull( tr.driver_id,"总体"), round( avg(grade),1) as avg_grade //把有取消记录的司机和总表连接,求出平均值,利用group by with rollup 一步到位 from tiaojian t inner join tb_get_car_order tr on tr.driver_id=t.t.driver_id group by tr.driver_id with rollup