CREATE TABLE time_interval (period TEXT, begin_time INT, end_time INT)
CREATE TABLE food_service (meal_code TEXT, meal_number INT, compartment TEXT, meal_description VARCHAR)
CREATE TABLE aircraft (aircraft_code VARCHAR, aircraft_description VARCHAR, manufacturer VARCHAR, basic_type VARCHAR, engines INT, propulsion VARCHAR, wide_body VARCHAR, wing_span INT, length INT, weight INT, capacity INT, pay_load INT, cruising_speed INT, range_miles INT, pressurized VARCHAR)
CREATE TABLE airline (airline_code VARCHAR, airline_name TEXT, note TEXT)
CREATE TABLE fare (fare_id INT, from_airport VARCHAR, to_airport VARCHAR, fare_basis_code TEXT, fare_airline TEXT, restriction_code TEXT, one_direction_cost INT, round_trip_cost INT, round_trip_required VARCHAR)
CREATE TABLE ground_service (city_code TEXT, airport_code TEXT, transport_type TEXT, ground_fare INT)
CREATE TABLE flight_stop (flight_id INT, stop_number INT, stop_days TEXT, stop_airport TEXT, arrival_time INT, arrival_airline TEXT, arrival_flight_number INT, departure_time INT, departure_airline TEXT, departure_flight_number INT, stop_time INT)
CREATE TABLE state (state_code TEXT, state_name TEXT, country_name TEXT)
CREATE TABLE flight_fare (flight_id INT, fare_id INT)
CREATE TABLE airport_service (city_code VARCHAR, airport_code VARCHAR, miles_distant INT, direction VARCHAR, minutes_distant INT)
CREATE TABLE fare_basis (fare_basis_code TEXT, booking_class TEXT, class_type TEXT, premium TEXT, economy TEXT, discounted TEXT, night TEXT, season TEXT, basis_days TEXT)
CREATE TABLE time_zone (time_zone_code TEXT, time_zone_name TEXT, hours_from_gmt INT)
CREATE TABLE restriction (restriction_code TEXT, advance_purchase INT, stopovers TEXT, saturday_stay_required TEXT, minimum_stay INT, maximum_stay INT, application TEXT, no_discounts TEXT)
CREATE TABLE date_day (month_number INT, day_number INT, year INT, day_name VARCHAR)
CREATE TABLE airport (airport_code VARCHAR, airport_name TEXT, airport_location TEXT, state_code VARCHAR, country_name VARCHAR, time_zone_code VARCHAR, minimum_connect_time INT)
CREATE TABLE city (city_code VARCHAR, city_name VARCHAR, state_code VARCHAR, country_name VARCHAR, time_zone_code VARCHAR)
CREATE TABLE flight (aircraft_code_sequence TEXT, airline_code VARCHAR, airline_flight TEXT, arrival_time INT, connections INT, departure_time INT, dual_carrier TEXT, flight_days TEXT, flight_id INT, flight_number INT, from_airport VARCHAR, meal_code TEXT, stops INT, time_elapsed INT, to_airport VARCHAR)
CREATE TABLE code_description (code VARCHAR, description TEXT)
CREATE TABLE compartment_class (compartment VARCHAR, class_type VARCHAR)
CREATE TABLE equipment_sequence (aircraft_code_sequence VARCHAR, aircraft_code VARCHAR)
CREATE TABLE month (month_number INT, month_name TEXT)
CREATE TABLE class_of_service (booking_class VARCHAR, rank INT, class_description TEXT)
CREATE TABLE dual_carrier (main_airline VARCHAR, low_flight_number INT, high_flight_number INT, dual_airline VARCHAR, service_name TEXT)
CREATE TABLE days (days_code VARCHAR, day_name VARCHAR)
CREATE TABLE flight_leg (flight_id INT, leg_number INT, leg_flight INT)

i need a flight leaving KANSAS CITY to CHICAGO leaving next wednesday and returning the following day
SELECT DISTINCT flight_id FROM flight WHERE (((flight_days IN (SELECT DAYSalias0.days_code FROM days AS DAYSalias0 WHERE DAYSalias0.day_name IN (SELECT DATE_DAYalias0.day_name FROM date_day AS DATE_DAYalias0 WHERE DATE_DAYalias0.day_number = 23 AND DATE_DAYalias0.month_number = 4 AND DATE_DAYalias0.year = 1991)) AND to_airport IN (SELECT AIRPORT_SERVICEalias1.airport_code FROM airport_service AS AIRPORT_SERVICEalias1 WHERE AIRPORT_SERVICEalias1.city_code IN (SELECT CITYalias1.city_code FROM city AS CITYalias1 WHERE CITYalias1.city_name = 'CHICAGO'))) AND from_airport IN (SELECT AIRPORT_SERVICEalias0.airport_code FROM airport_service AS AIRPORT_SERVICEalias0 WHERE AIRPORT_SERVICEalias0.city_code IN (SELECT CITYalias0.city_code FROM city AS CITYalias0 WHERE CITYalias0.city_name = 'KANSAS CITY'))) OR ((flight_days IN (SELECT DAYSalias1.days_code FROM days AS DAYSalias1 WHERE DAYSalias1.day_name IN (SELECT DATE_DAYalias1.day_name FROM date_day AS DATE_DAYalias1 WHERE DATE_DAYalias1.day_number = 23 AND DATE_DAYalias1.month_number = 4 AND DATE_DAYalias1.year = 1991)) AND to_airport IN (SELECT AIRPORT_SERVICEalias3.airport_code FROM airport_service AS AIRPORT_SERVICEalias3 WHERE AIRPORT_SERVICEalias3.city_code IN (SELECT CITYalias3.city_code FROM city AS CITYalias3 WHERE CITYalias3.city_name = 'KANSAS CITY'))) AND from_airport IN (SELECT AIRPORT_SERVICEalias2.airport_code FROM airport_service AS AIRPORT_SERVICEalias2 WHERE AIRPORT_SERVICEalias2.city_code IN (SELECT CITYalias2.city_code FROM city AS CITYalias2 WHERE CITYalias2.city_name = 'CHICAGO'))))
WITH "_u_0" AS (SELECT "DATE_DAYalias0"."day_name" FROM "date_day" AS "DATE_DAYalias0" WHERE "DATE_DAYalias0"."day_number" = 23 AND "DATE_DAYalias0"."month_number" = 4 AND "DATE_DAYalias0"."year" = 1991 GROUP BY "day_name"), "_u_1" AS (SELECT "DAYSalias0"."days_code" FROM "days" AS "DAYSalias0" LEFT JOIN "_u_0" AS "_u_0" ON "DAYSalias0"."day_name" = "_u_0"."" WHERE NOT "_u_0"."" IS NULL GROUP BY "days_code"), "_u_10" AS (SELECT "CITYalias3"."city_code" FROM "city" AS "CITYalias3" WHERE "CITYalias3"."city_name" = 'KANSAS CITY' GROUP BY "city_code"), "_u_11" AS (SELECT "AIRPORT_SERVICEalias3"."airport_code" FROM "airport_service" AS "AIRPORT_SERVICEalias3" LEFT JOIN "_u_10" AS "_u_10" ON "AIRPORT_SERVICEalias3"."city_code" = "_u_10"."" WHERE NOT "_u_10"."" IS NULL GROUP BY "airport_code"), "_u_12" AS (SELECT "CITYalias1"."city_code" FROM "city" AS "CITYalias1" WHERE "CITYalias1"."city_name" = 'CHICAGO' GROUP BY "city_code"), "_u_13" AS (SELECT "AIRPORT_SERVICEalias1"."airport_code" FROM "airport_service" AS "AIRPORT_SERVICEalias1" LEFT JOIN "_u_12" AS "_u_12" ON "AIRPORT_SERVICEalias1"."city_code" = "_u_12"."" WHERE NOT "_u_12"."" IS NULL GROUP BY "airport_code"), "_u_15" AS (SELECT "AIRPORT_SERVICEalias3"."airport_code" FROM "airport_service" AS "AIRPORT_SERVICEalias3" LEFT JOIN "_u_10" AS "_u_14" ON "AIRPORT_SERVICEalias3"."city_code" = "_u_14"."" WHERE NOT "_u_14"."" IS NULL GROUP BY "airport_code"), "_u_16" AS (SELECT "DATE_DAYalias1"."day_name" FROM "date_day" AS "DATE_DAYalias1" WHERE "DATE_DAYalias1"."day_number" = 23 AND "DATE_DAYalias1"."month_number" = 4 AND "DATE_DAYalias1"."year" = 1991 GROUP BY "day_name"), "_u_17" AS (SELECT "DAYSalias1"."days_code" FROM "days" AS "DAYSalias1" LEFT JOIN "_u_16" AS "_u_16" ON "DAYSalias1"."day_name" = "_u_16"."" WHERE NOT "_u_16"."" IS NULL GROUP BY "days_code"), "_u_18" AS (SELECT "CITYalias0"."city_code" FROM "city" AS "CITYalias0" WHERE "CITYalias0"."city_name" = 'KANSAS CITY' GROUP BY "city_code"), "_u_19" AS (SELECT "AIRPORT_SERVICEalias0"."airport_code" FROM "airport_service" AS "AIRPORT_SERVICEalias0" LEFT JOIN "_u_18" AS "_u_18" ON "AIRPORT_SERVICEalias0"."city_code" = "_u_18"."" WHERE NOT "_u_18"."" IS NULL GROUP BY "airport_code"), "_u_21" AS (SELECT "AIRPORT_SERVICEalias0"."airport_code" FROM "airport_service" AS "AIRPORT_SERVICEalias0" LEFT JOIN "_u_18" AS "_u_20" ON "AIRPORT_SERVICEalias0"."city_code" = "_u_20"."" WHERE NOT "_u_20"."" IS NULL GROUP BY "airport_code"), "_u_23" AS (SELECT "AIRPORT_SERVICEalias3"."airport_code" FROM "airport_service" AS "AIRPORT_SERVICEalias3" LEFT JOIN "_u_10" AS "_u_22" ON "AIRPORT_SERVICEalias3"."city_code" = "_u_22"."" WHERE NOT "_u_22"."" IS NULL GROUP BY "airport_code"), "_u_25" AS (SELECT "DAYSalias0"."days_code" FROM "days" AS "DAYSalias0" LEFT JOIN "_u_0" AS "_u_24" ON "DAYSalias0"."day_name" = "_u_24"."" WHERE NOT "_u_24"."" IS NULL GROUP BY "days_code"), "_u_26" AS (SELECT "CITYalias2"."city_code" FROM "city" AS "CITYalias2" WHERE "CITYalias2"."city_name" = 'CHICAGO' GROUP BY "city_code"), "_u_27" AS (SELECT "AIRPORT_SERVICEalias2"."airport_code" FROM "airport_service" AS "AIRPORT_SERVICEalias2" LEFT JOIN "_u_26" AS "_u_26" ON "AIRPORT_SERVICEalias2"."city_code" = "_u_26"."" WHERE NOT "_u_26"."" IS NULL GROUP BY "airport_code"), "_u_29" AS (SELECT "AIRPORT_SERVICEalias2"."airport_code" FROM "airport_service" AS "AIRPORT_SERVICEalias2" LEFT JOIN "_u_26" AS "_u_28" ON "AIRPORT_SERVICEalias2"."city_code" = "_u_28"."" WHERE NOT "_u_28"."" IS NULL GROUP BY "airport_code"), "_u_3" AS (SELECT "DAYSalias1"."days_code" FROM "days" AS "DAYSalias1" LEFT JOIN "_u_16" AS "_u_2" ON "DAYSalias1"."day_name" = "_u_2"."" WHERE NOT "_u_2"."" IS NULL GROUP BY "days_code"), "_u_31" AS (SELECT "AIRPORT_SERVICEalias1"."airport_code" FROM "airport_service" AS "AIRPORT_SERVICEalias1" LEFT JOIN "_u_12" AS "_u_30" ON "AIRPORT_SERVICEalias1"."city_code" = "_u_30"."" WHERE NOT "_u_30"."" IS NULL GROUP BY "airport_code"), "_u_33" AS (SELECT "AIRPORT_SERVICEalias0"."airport_code" FROM "airport_service" AS "AIRPORT_SERVICEalias0" LEFT JOIN "_u_18" AS "_u_32" ON "AIRPORT_SERVICEalias0"."city_code" = "_u_32"."" WHERE NOT "_u_32"."" IS NULL GROUP BY "airport_code"), "_u_35" AS (SELECT "AIRPORT_SERVICEalias2"."airport_code" FROM "airport_service" AS "AIRPORT_SERVICEalias2" LEFT JOIN "_u_26" AS "_u_34" ON "AIRPORT_SERVICEalias2"."city_code" = "_u_34"."" WHERE NOT "_u_34"."" IS NULL GROUP BY "airport_code"), "_u_5" AS (SELECT "DAYSalias1"."days_code" FROM "days" AS "DAYSalias1" LEFT JOIN "_u_16" AS "_u_4" ON "DAYSalias1"."day_name" = "_u_4"."" WHERE NOT "_u_4"."" IS NULL GROUP BY "days_code"), "_u_7" AS (SELECT "AIRPORT_SERVICEalias1"."airport_code" FROM "airport_service" AS "AIRPORT_SERVICEalias1" LEFT JOIN "_u_12" AS "_u_6" ON "AIRPORT_SERVICEalias1"."city_code" = "_u_6"."" WHERE NOT "_u_6"."" IS NULL GROUP BY "airport_code"), "_u_9" AS (SELECT "DAYSalias0"."days_code" FROM "days" AS "DAYSalias0" LEFT JOIN "_u_0" AS "_u_8" ON "DAYSalias0"."day_name" = "_u_8"."" WHERE NOT "_u_8"."" IS NULL GROUP BY "days_code") SELECT DISTINCT "flight_id" FROM "flight" LEFT JOIN "_u_1" AS "_u_1" ON "_u_1"."" = "flight_days" LEFT JOIN "_u_11" AS "_u_11" ON "_u_11"."" = "to_airport" LEFT JOIN "_u_13" AS "_u_13" ON "_u_13"."" = "to_airport" LEFT JOIN "_u_15" AS "_u_15" ON "_u_15"."" = "to_airport" LEFT JOIN "_u_17" AS "_u_17" ON "_u_17"."" = "flight_days" LEFT JOIN "_u_19" AS "_u_19" ON "_u_19"."" = "from_airport" LEFT JOIN "_u_21" AS "_u_21" ON "_u_21"."" = "from_airport" LEFT JOIN "_u_23" AS "_u_23" ON "_u_23"."" = "to_airport" LEFT JOIN "_u_25" AS "_u_25" ON "_u_25"."" = "flight_days" LEFT JOIN "_u_27" AS "_u_27" ON "_u_27"."" = "from_airport" LEFT JOIN "_u_29" AS "_u_29" ON "_u_29"."" = "from_airport" LEFT JOIN "_u_3" AS "_u_3" ON "_u_3"."" = "flight_days" LEFT JOIN "_u_31" AS "_u_31" ON "_u_31"."" = "to_airport" LEFT JOIN "_u_33" AS "_u_33" ON "_u_33"."" = "from_airport" LEFT JOIN "_u_35" AS "_u_35" ON "_u_35"."" = "from_airport" LEFT JOIN "_u_5" AS "_u_5" ON "_u_5"."" = "flight_days" LEFT JOIN "_u_7" AS "_u_7" ON "_u_7"."" = "to_airport" LEFT JOIN "_u_9" AS "_u_9" ON "_u_9"."" = "flight_days" WHERE (NOT "_u_1"."" IS NULL OR NOT "_u_3"."" IS NULL) AND (NOT "_u_11"."" IS NULL OR NOT "_u_9"."" IS NULL) AND (NOT "_u_13"."" IS NULL OR NOT "_u_15"."" IS NULL) AND (NOT "_u_17"."" IS NULL OR NOT "_u_19"."" IS NULL) AND (NOT "_u_21"."" IS NULL OR NOT "_u_23"."" IS NULL) AND (NOT "_u_25"."" IS NULL OR NOT "_u_27"."" IS NULL) AND (NOT "_u_29"."" IS NULL OR NOT "_u_31"."" IS NULL) AND (NOT "_u_33"."" IS NULL OR NOT "_u_35"."" IS NULL) AND (NOT "_u_5"."" IS NULL OR NOT "_u_7"."" IS NULL)