趁人少分享一下自己的第一个双百哈哈哈
内部一个筛选 先选取符合条件的司机的订单量,总收入,外面再套一个求avg就行了。
select t.city,round(avg(avg_order_num),3),round(avg(avg_income),3)
from (
select driver_id,city,count(o.order_id) as avg_order_num, sum(fare) as avg_income
from tb_get_car_record as r
join tb_get_car_order as o
on r.order_id = o.order_id
where city = '北京' and event_time between '2021-10-01' and '2021-10-07'
group by driver_id
having count(*) > 2
) as t
group by city