Select airport airport_code , AVG(cder/31) flights_count from
(Select distinct airport , sum(cdep) cder from
(Select distinct departure_airport as airport, count(*) cdep from flights
where actual_departure is not null and actual_departure>'20170801'
group by departure_airport
union all
Select distinct arrival_airport , count(*) cdep from flights
where actual_arrival is not null and actual_arrival>'20170801'
group by arrival_airport) l
group by airport) k
group by airport
having AVG(cder) <=3