首先题目要求是:请统计2021年国庆7天期间在北京市接单至少3次的司机的平均接单数和平均兼职收入
那么我们先把在北京国庆期间接单至少3次以上的司机筛选出来
select driver_id
        from tb_get_car_order
        join tb_get_car_record
        on tb_get_car_order.order_id=tb_get_car_record.order_id
        where date(order_time) between '2021-10-01' and '2021-10-07'
         and city='北京'
        group by driver_id
        having count(distinct tb_get_car_order.order_id)>=3
然后再將筛选出来的司机,和两个原表进行连接,求出平均接单数和平均兼职收入,
select city,round(count(distinct a.order_id)/count(distinct t.driver_id),3),round(sum(fare)/count(distinct t.driver_id),3)
from tb_get_car_order a
join tb_get_car_record b
on a.uid=b.uid
join
        (select driver_id
        from tb_get_car_order
        join tb_get_car_record
        on tb_get_car_order.order_id=tb_get_car_record.order_id
        where date(order_time) between '2021-10-01' and '2021-10-07'
         and city='北京'
        group by driver_id
        having count(distinct tb_get_car_order.order_id)>=3
         ) t
on a.driver_id=t.driver_id
where date(a.order_time) between '2021-10-01' and '2021-10-07'
and city='北京';