with t1 as(select distinct f.departure_airport as departure_airport,count(ticket_no) as cnt1
from flights f
right join boarding_passes bp on f.flight_id=bp.flight_id
where extract(year from actual_departure)=2017 and extract(month from actual_departure)=8
group by 1),t2 as(select distinct f.departure_airport as departure_airport,count(s.seat_no) as cnt2
from flights f right join seats s on f. aircraft_code=s.aircraft_code
where extract(year from actual_departure)=2017 and extract(month from actual_departure)=8
group by 1)
select t1.departure_airport,round(cnt1::numeric/cnt2*100,2) as average_flights_occupancy
from t1 join t2 on t1.departure_airport=t2.departure_airport
order by 1