思路:
①根据城市和司机id分组,选出北京、司机id、国庆日期内接单数、收入形成表TB3;
②对TB3子查询,根据城市分组,计算相关平均值即可。
select city, 
round(sum(order_num)/count(driver_id),3),
round(sum(income)/count(driver_id),3)
from (
select city, driver_id, count(order_time) order_num, sum(fare) income
from tb_get_car_order tb2 left join tb_get_car_record tb1
on tb1.uid=tb2.uid and tb1.order_id=tb2.order_id
where date(order_time) between '2021-10-01' and '2021-10-07'
group by city, driver_id
having city='北京' and count(order_time)>=3) as tb3
group by city