SELECTN_WEEK as week_number,COUNT(TICKET_NO) as ticket_amount,festival_week,festival_nameFROM(SELECTticket_no,flight_id,n_weekFROMticket_flights LEFT JOIN (SELECTflight_id as flight_ids,EXTRACT(WEEK FROM arrival_time) as n_weekFROM flightsWHEREarrival_airport IN (SELECT airport_codeFROM airportsWHERE city = 'Москва')AND arrival_time BETWEEN '2018-07-23' AND '2018-09-30')AS msc_fly ON ticket_flights.flight_id = msc_fly.flight_ids) as msc_ticket_flightsLEFT JOIN(SELECTfestival_name,EXTRACT(WEEK FROM festival_date) as festival_weekFROM festivalsWHERE festival_city = 'Москва') as msc_festivalsON msc_ticket_flights.n_week = msc_festivals.festival_weekWHERE n_week IS NOT NULLGROUP BY week_number, festival_week, festival_name