Untitled
3 years ago in Plain Text
SELECT
N_WEEK as week_number,
COUNT(TICKET_NO) as ticket_amount,
festival_week,
festival_name
FROM
(
SELECT
ticket_no,
flight_id,
n_week
FROM
ticket_flights LEFT JOIN (
SELECT
flight_id as flight_ids,
EXTRACT(WEEK FROM arrival_time) as n_week
FROM flights
WHERE
arrival_airport IN (SELECT airport_code
FROM airports
WHERE 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_flights
LEFT JOIN
(
SELECT
festival_name,
EXTRACT(WEEK FROM festival_date) as festival_week
FROM festivals
WHERE festival_city = 'Москва'
) as msc_festivals
ON msc_ticket_flights.n_week = msc_festivals.festival_week
WHERE n_week IS NOT NULL
GROUP BY week_number, festival_week, festival_name