题解 | #有取消订单记录的司机平均评分#
有取消订单记录的司机平均评分
http://www.nowcoder.com/practice/f022c9ec81044d4bb7e0711ab794531a
(select
t.driver_id driver_id,
round(sum(t.grade)/count(1), 1) avg_grade
from
tb_get_car_order as t right join
(select driver_id from tb_get_car_order where date_format(order_time,'%Y-%m') = '2021-10'
and start_time is null) as m
on t.driver_id = m.driver_id
where t.start_time is not null
group by t.driver_id
order by t.driver_id)
union all
(select
"总体" driver_id,
round(sum(t.grade)/count(1), 1) avg_grade
from
tb_get_car_order as t right join
(select driver_id from tb_get_car_order where date_format(order_time,'%Y-%m') = '2021-10'
and start_time is null) as m
on t.driver_id = m.driver_id
where t.start_time is not null
group by 1)