db_id
stringclasses
146 values
question
stringlengths
3
224
sql
stringlengths
18
577
database_schema
stringclasses
146 values
activity_1
What are the first names of the faculty members playing both Canoeing and Kayaking?
SELECT T1.lname FROM Faculty AS T1 JOIN Faculty_participates_in AS T2 ON T1.facID = T2.facID JOIN activity AS T3 ON T2.actid = T2.actid WHERE T3.activity_name = 'Canoeing' INTERSECT SELECT T1.lname FROM Faculty AS T1 JOIN Faculty_participates_in AS T2 ON T1.facID = T2.facID JOIN activity AS T3 ON T2.actid = T2.actid WHERE T3.activity_name = 'Kayaking'
CREATE TABLE Activity ( actid INTEGER PRIMARY KEY, activity_name varchar(25) ) 3 rows from Activity table: actid activity_name 770 Mountain Climbing 771 Canoeing 772 Kayaking CREATE TABLE Participates_in ( stuid INTEGER, actid INTEGER, FOREIGN KEY(stuid) REFERENCES Student(StuID), FOREIGN KEY(actid) REFERENCES Activity(actid) ) 3 rows from Participates_in table: stuid actid 1001 770 1001 771 1001 777 CREATE TABLE Faculty_Participates_in ( FacID INTEGER, actid INTEGER, FOREIGN KEY(FacID) REFERENCES Faculty(FacID), FOREIGN KEY(actid) REFERENCES Activity(actid) ) 3 rows from Faculty_Participates_in table: FacID actid 1082 784 1082 785 1082 790 CREATE TABLE Student ( StuID INTEGER PRIMARY KEY, LName VARCHAR(12), Fname VARCHAR(12), Age INTEGER, Sex VARCHAR(1), Major INTEGER, Advisor INTEGER, city_code VARCHAR(3) ) 3 rows from Student table: StuID LName Fname Age Sex Major Advisor city_code 1001 Smith Linda 18 F 600 1121 BAL 1002 Kim Tracy 19 F 600 7712 HKG 1003 Jones Shiela 21 F 600 7792 WAS CREATE TABLE Faculty ( FacID INTEGER PRIMARY KEY, Lname VARCHAR(15), Fname VARCHAR(15), Rank VARCHAR(15), Sex VARCHAR(1), Phone INTEGER, Room VARCHAR(5), Building VARCHAR(13) ) 3 rows from Faculty table: FacID Lname Fname Rank Sex Phone Room Building 1082 Giuliano Mark Instructor M 2424 224 NEB 1121 Goodrich Michael Professor M 3593 219 NEB 1148 Masson Gerald Professor M 3402 224B NEB
activity_1
Find the ids of the students who participate in Canoeing and Kayaking.
SELECT T1.stuid FROM participates_in AS T1 JOIN activity AS T2 ON T2.actid = T2.actid WHERE T2.activity_name = 'Canoeing' INTERSECT SELECT T1.stuid FROM participates_in AS T1 JOIN activity AS T2 ON T2.actid = T2.actid WHERE T2.activity_name = 'Kayaking'
CREATE TABLE Activity ( actid INTEGER PRIMARY KEY, activity_name varchar(25) ) 3 rows from Activity table: actid activity_name 770 Mountain Climbing 771 Canoeing 772 Kayaking CREATE TABLE Participates_in ( stuid INTEGER, actid INTEGER, FOREIGN KEY(stuid) REFERENCES Student(StuID), FOREIGN KEY(actid) REFERENCES Activity(actid) ) 3 rows from Participates_in table: stuid actid 1001 770 1001 771 1001 777 CREATE TABLE Faculty_Participates_in ( FacID INTEGER, actid INTEGER, FOREIGN KEY(FacID) REFERENCES Faculty(FacID), FOREIGN KEY(actid) REFERENCES Activity(actid) ) 3 rows from Faculty_Participates_in table: FacID actid 1082 784 1082 785 1082 790 CREATE TABLE Student ( StuID INTEGER PRIMARY KEY, LName VARCHAR(12), Fname VARCHAR(12), Age INTEGER, Sex VARCHAR(1), Major INTEGER, Advisor INTEGER, city_code VARCHAR(3) ) 3 rows from Student table: StuID LName Fname Age Sex Major Advisor city_code 1001 Smith Linda 18 F 600 1121 BAL 1002 Kim Tracy 19 F 600 7712 HKG 1003 Jones Shiela 21 F 600 7792 WAS CREATE TABLE Faculty ( FacID INTEGER PRIMARY KEY, Lname VARCHAR(15), Fname VARCHAR(15), Rank VARCHAR(15), Sex VARCHAR(1), Phone INTEGER, Room VARCHAR(5), Building VARCHAR(13) ) 3 rows from Faculty table: FacID Lname Fname Rank Sex Phone Room Building 1082 Giuliano Mark Instructor M 2424 224 NEB 1121 Goodrich Michael Professor M 3593 219 NEB 1148 Masson Gerald Professor M 3402 224B NEB
activity_1
Which students participate in both Canoeing and Kayaking as their activities? Tell me their student ids.
SELECT T1.stuid FROM participates_in AS T1 JOIN activity AS T2 ON T2.actid = T2.actid WHERE T2.activity_name = 'Canoeing' INTERSECT SELECT T1.stuid FROM participates_in AS T1 JOIN activity AS T2 ON T2.actid = T2.actid WHERE T2.activity_name = 'Kayaking'
CREATE TABLE Activity ( actid INTEGER PRIMARY KEY, activity_name varchar(25) ) 3 rows from Activity table: actid activity_name 770 Mountain Climbing 771 Canoeing 772 Kayaking CREATE TABLE Participates_in ( stuid INTEGER, actid INTEGER, FOREIGN KEY(stuid) REFERENCES Student(StuID), FOREIGN KEY(actid) REFERENCES Activity(actid) ) 3 rows from Participates_in table: stuid actid 1001 770 1001 771 1001 777 CREATE TABLE Faculty_Participates_in ( FacID INTEGER, actid INTEGER, FOREIGN KEY(FacID) REFERENCES Faculty(FacID), FOREIGN KEY(actid) REFERENCES Activity(actid) ) 3 rows from Faculty_Participates_in table: FacID actid 1082 784 1082 785 1082 790 CREATE TABLE Student ( StuID INTEGER PRIMARY KEY, LName VARCHAR(12), Fname VARCHAR(12), Age INTEGER, Sex VARCHAR(1), Major INTEGER, Advisor INTEGER, city_code VARCHAR(3) ) 3 rows from Student table: StuID LName Fname Age Sex Major Advisor city_code 1001 Smith Linda 18 F 600 1121 BAL 1002 Kim Tracy 19 F 600 7712 HKG 1003 Jones Shiela 21 F 600 7792 WAS CREATE TABLE Faculty ( FacID INTEGER PRIMARY KEY, Lname VARCHAR(15), Fname VARCHAR(15), Rank VARCHAR(15), Sex VARCHAR(1), Phone INTEGER, Room VARCHAR(5), Building VARCHAR(13) ) 3 rows from Faculty table: FacID Lname Fname Rank Sex Phone Room Building 1082 Giuliano Mark Instructor M 2424 224 NEB 1121 Goodrich Michael Professor M 3593 219 NEB 1148 Masson Gerald Professor M 3402 224B NEB
flight_4
Find the name of the airport in the city of Goroka.
SELECT name FROM airports WHERE city = 'Goroka'
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
What are the names of the airports in the city of Goroka?
SELECT name FROM airports WHERE city = 'Goroka'
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
Find the name, city, country, and altitude (or elevation) of the airports in the city of New York.
SELECT name , city , country , elevation FROM airports WHERE city = 'New York'
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
What is the name, city, country, and elevation for every airport in the city of New York?
SELECT name , city , country , elevation FROM airports WHERE city = 'New York'
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
How many airlines are there?
SELECT count(*) FROM airlines
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
What is the total number of airlines?
SELECT count(*) FROM airlines
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
How many airlines does Russia has?
SELECT count(*) FROM airlines WHERE country = 'Russia'
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
What is the number of airlines based in Russia?
SELECT count(*) FROM airlines WHERE country = 'Russia'
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
What is the maximum elevation of all airports in the country of Iceland?
SELECT max(elevation) FROM airports WHERE country = 'Iceland'
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
What is the highest elevation of an airport in the country of Iceland?
SELECT max(elevation) FROM airports WHERE country = 'Iceland'
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
Find the name of the airports located in Cuba or Argentina.
SELECT name FROM airports WHERE country = 'Cuba' OR country = 'Argentina'
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
What are the names of all airports in Cuba or Argentina?
SELECT name FROM airports WHERE country = 'Cuba' OR country = 'Argentina'
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
Find the country of the airlines whose name starts with 'Orbit'.
SELECT country FROM airlines WHERE name LIKE 'Orbit%'
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
What are the countries of all airlines whose names start with Orbit?
SELECT country FROM airlines WHERE name LIKE 'Orbit%'
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
Find the name of airports whose altitude is between -50 and 50.
SELECT name FROM airports WHERE elevation BETWEEN -50 AND 50
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
What are the names of all airports whose elevation is between -50 and 50?
SELECT name FROM airports WHERE elevation BETWEEN -50 AND 50
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
Which country is the airport that has the highest altitude located in?
SELECT country FROM airports ORDER BY elevation DESC LIMIT 1
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
What is the country of the airport with the highest elevation?
SELECT country FROM airports ORDER BY elevation DESC LIMIT 1
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
Find the number of airports whose name contain the word 'International'.
SELECT count(*) FROM airports WHERE name LIKE '%International%'
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
How many airports' names have the word Interanation in them?
SELECT count(*) FROM airports WHERE name LIKE '%International%'
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
How many different cities do have some airport in the country of Greenland?
SELECT count(DISTINCT city) FROM airports WHERE country = 'Greenland'
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
In how many cities are there airports in the country of Greenland?
SELECT count(DISTINCT city) FROM airports WHERE country = 'Greenland'
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
Find the number of routes operated by American Airlines.
SELECT count(*) FROM airlines AS T1 JOIN routes AS T2 ON T1.alid = T2.alid WHERE T1.name = 'American Airlines'
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
How many routes does American Airlines operate?
SELECT count(*) FROM airlines AS T1 JOIN routes AS T2 ON T1.alid = T2.alid WHERE T1.name = 'American Airlines'
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
Find the number of routes whose destination airports are in Canada.
SELECT count(*) FROM airports AS T1 JOIN routes AS T2 ON T1.apid = T2.dst_apid WHERE country = 'Canada'
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
How many routes end in a Canadian airport?
SELECT count(*) FROM airports AS T1 JOIN routes AS T2 ON T1.apid = T2.dst_apid WHERE country = 'Canada'
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
Find the name, city, and country of the airport that has the lowest altitude.
SELECT name , city , country FROM airports ORDER BY elevation LIMIT 1
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
What is the name, city, and country of the airport with the lowest altitude?
SELECT name , city , country FROM airports ORDER BY elevation LIMIT 1
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
Find the name, city, and country of the airport that has the highest latitude.
SELECT name , city , country FROM airports ORDER BY elevation DESC LIMIT 1
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
What is the name, city, and country of the airport with the highest elevation?
SELECT name , city , country FROM airports ORDER BY elevation DESC LIMIT 1
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
Find the name and city of the airport which is the destination of the most number of routes.
SELECT T1.name , T1.city , T2.dst_apid FROM airports AS T1 JOIN routes AS T2 ON T1.apid = T2.dst_apid GROUP BY T2.dst_apid ORDER BY count(*) DESC LIMIT 1
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
What is the name and city of the airport that the most routes end at?
SELECT T1.name , T1.city , T2.dst_apid FROM airports AS T1 JOIN routes AS T2 ON T1.apid = T2.dst_apid GROUP BY T2.dst_apid ORDER BY count(*) DESC LIMIT 1
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
Find the names of the top 10 airlines that operate the most number of routes.
SELECT T1.name , T2.alid FROM airlines AS T1 JOIN routes AS T2 ON T1.alid = T2.alid GROUP BY T2.alid ORDER BY count(*) DESC LIMIT 10
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
For the airline ids with the top 10 most routes operated, what are their names?
SELECT T1.name , T2.alid FROM airlines AS T1 JOIN routes AS T2 ON T1.alid = T2.alid GROUP BY T2.alid ORDER BY count(*) DESC LIMIT 10
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
Find the name and city of the airport which is the source for the most number of flight routes.
SELECT T1.name , T1.city , T2.src_apid FROM airports AS T1 JOIN routes AS T2 ON T1.apid = T2.src_apid GROUP BY T2.src_apid ORDER BY count(*) DESC LIMIT 1
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
What is the name and city of the airport from most of the routes start?
SELECT T1.name , T1.city , T2.src_apid FROM airports AS T1 JOIN routes AS T2 ON T1.apid = T2.src_apid GROUP BY T2.src_apid ORDER BY count(*) DESC LIMIT 1
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
Find the number of different airports which are the destinations of the American Airlines.
SELECT count(DISTINCT dst_apid) FROM airlines AS T1 JOIN routes AS T2 ON T1.alid = T2.alid WHERE T1.name = 'American Airlines'
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
What is the number of different different airports that are destinations for American Airlines?
SELECT count(DISTINCT dst_apid) FROM airlines AS T1 JOIN routes AS T2 ON T1.alid = T2.alid WHERE T1.name = 'American Airlines'
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
Which countries has the most number of airlines?
SELECT country FROM airlines GROUP BY country ORDER BY count(*) DESC LIMIT 1
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
What is the name of the country with the most number of home airlines?
SELECT country FROM airlines GROUP BY country ORDER BY count(*) DESC LIMIT 1
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
Which countries has the most number of airlines whose active status is 'Y'?
SELECT country FROM airlines WHERE active = 'Y' GROUP BY country ORDER BY count(*) DESC LIMIT 1
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
What are the countries with the most airlines whose active status is Y?
SELECT country FROM airlines WHERE active = 'Y' GROUP BY country ORDER BY count(*) DESC LIMIT 1
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
List all countries and their number of airlines in the descending order of number of airlines.
SELECT country , count(*) FROM airlines GROUP BY country ORDER BY count(*) DESC
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
How many airlines operate out of each country in descending order?
SELECT country , count(*) FROM airlines GROUP BY country ORDER BY count(*) DESC
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
How many airports are there per country? Order the countries by decreasing number of airports.
SELECT count(*) , country FROM airports GROUP BY country ORDER BY count(*) DESC
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
What is the number of airports per country, ordered from most to least?
SELECT count(*) , country FROM airports GROUP BY country ORDER BY count(*) DESC
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
How many airports are there per city in the United States? Order the cities by decreasing number of airports.
SELECT count(*) , city FROM airports WHERE country = 'United States' GROUP BY city ORDER BY count(*) DESC
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
How many airports are there per city in the US ordered from most to least?
SELECT count(*) , city FROM airports WHERE country = 'United States' GROUP BY city ORDER BY count(*) DESC
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
Return the cities with more than 3 airports in the United States.
SELECT city FROM airports WHERE country = 'United States' GROUP BY city HAVING count(*) > 3
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
What is the number of cities in the United States with more than 3 airports?
SELECT city FROM airports WHERE country = 'United States' GROUP BY city HAVING count(*) > 3
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
How many cities are there that have more than 3 airports?
SELECT count(*) FROM (SELECT city FROM airports GROUP BY city HAVING count(*) > 3)
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
What is the count of cities with more than 3 airports?
SELECT count(*) FROM (SELECT city FROM airports GROUP BY city HAVING count(*) > 3)
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
List the cities which have more than one airport and number of airports.
SELECT city , count(*) FROM airports GROUP BY city HAVING count(*) > 1
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
What are the names of all cities with more than one airport and how many airports do they have?
SELECT city , count(*) FROM airports GROUP BY city HAVING count(*) > 1
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
List the cities which have more than 2 airports sorted by the number of airports.
SELECT city FROM airports GROUP BY city HAVING count(*) > 2 ORDER BY count(*)
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
What are the cities that have more than 2 airports sorted by number of airports?
SELECT city FROM airports GROUP BY city HAVING count(*) > 2 ORDER BY count(*)
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
Find the number of routes for each source airport and the airport name.
SELECT count(*) , T1.name FROM airports AS T1 JOIN routes AS T2 ON T1.apid = T2.src_apid GROUP BY T1.name
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
For each airport name, how many routes start at that airport?
SELECT count(*) , T1.name FROM airports AS T1 JOIN routes AS T2 ON T1.apid = T2.src_apid GROUP BY T1.name
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
Find the number of routes and airport name for each source airport, order the results by decreasing number of routes.
SELECT count(*) , T1.name FROM airports AS T1 JOIN routes AS T2 ON T1.apid = T2.src_apid GROUP BY T1.name ORDER BY count(*) DESC
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
For each airport name, how many routes start at that airport, ordered from most to least?
SELECT count(*) , T1.name FROM airports AS T1 JOIN routes AS T2 ON T1.apid = T2.src_apid GROUP BY T1.name ORDER BY count(*) DESC
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
Find the average elevation of all airports for each country.
SELECT avg(elevation) , country FROM airports GROUP BY country
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
For each country, what is the average elevation of that country's airports?
SELECT avg(elevation) , country FROM airports GROUP BY country
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
Find the cities which have exactly two airports.
SELECT city FROM airports GROUP BY city HAVING count(*) = 2
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
What are the cities with exactly two airports?
SELECT city FROM airports GROUP BY city HAVING count(*) = 2
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
For each country and airline name, how many routes are there?
SELECT T1.country , T1.name , count(*) FROM airlines AS T1 JOIN routes AS T2 ON T1.alid = T2.alid GROUP BY T1.country , T1.name
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
What is the total number of routes for each country and airline in that country?
SELECT T1.country , T1.name , count(*) FROM airlines AS T1 JOIN routes AS T2 ON T1.alid = T2.alid GROUP BY T1.country , T1.name
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
Find the number of routes with destination airports in Italy.
SELECT count(*) FROM routes AS T1 JOIN airports AS T2 ON T1.dst_apid = T2.apid WHERE T2.country = 'Italy'
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
What is the number of routes whose destinations are Italian airports?
SELECT count(*) FROM routes AS T1 JOIN airports AS T2 ON T1.dst_apid = T2.apid WHERE T2.country = 'Italy'
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
Return the number of routes with destination airport in Italy operated by the airline with name 'American Airlines'.
SELECT count(*) FROM routes AS T1 JOIN airports AS T2 ON T1.dst_apid = T2.apid JOIN airlines AS T3 ON T1.alid = T3.alid WHERE T2.country = 'Italy' AND T3.name = 'American Airlines'
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
What is the number of routes operated by the airline American Airlines whose destinations are in Italy?
SELECT count(*) FROM routes AS T1 JOIN airports AS T2 ON T1.dst_apid = T2.apid JOIN airlines AS T3 ON T1.alid = T3.alid WHERE T2.country = 'Italy' AND T3.name = 'American Airlines'
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
Find the number of routes that have destination John F Kennedy International Airport.
SELECT count(*) FROM airports AS T1 JOIN routes AS T2 ON T1.apid = T2.dst_apid WHERE T1.name = 'John F Kennedy International Airport'
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
What is the number of routes that end at John F Kennedy International Airport?
SELECT count(*) FROM airports AS T1 JOIN routes AS T2 ON T1.apid = T2.dst_apid WHERE T1.name = 'John F Kennedy International Airport'
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
Find the number of routes from the United States to Canada.
SELECT count(*) FROM routes WHERE dst_apid IN (SELECT apid FROM airports WHERE country = 'Canada') AND src_apid IN (SELECT apid FROM airports WHERE country = 'United States')
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
How many routes go from the United States to Canada?
SELECT count(*) FROM routes WHERE dst_apid IN (SELECT apid FROM airports WHERE country = 'Canada') AND src_apid IN (SELECT apid FROM airports WHERE country = 'United States')
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
Find the id of routes whose source and destination airports are in the United States.
SELECT rid FROM routes WHERE dst_apid IN (SELECT apid FROM airports WHERE country = 'United States') AND src_apid IN (SELECT apid FROM airports WHERE country = 'United States')
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
What is the id of the routes whose source and destination airports are in the United States?
SELECT rid FROM routes WHERE dst_apid IN (SELECT apid FROM airports WHERE country = 'United States') AND src_apid IN (SELECT apid FROM airports WHERE country = 'United States')
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
Find the name of airline which runs the most number of routes.
SELECT T1.name FROM airlines AS T1 JOIN routes AS T2 ON T1.alid = T2.alid GROUP BY T1.name ORDER BY count(*) DESC LIMIT 1
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
What is the name of the airline with the most routes?
SELECT T1.name FROM airlines AS T1 JOIN routes AS T2 ON T1.alid = T2.alid GROUP BY T1.name ORDER BY count(*) DESC LIMIT 1
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
Find the busiest source airport that runs most number of routes in China.
SELECT T1.name FROM airports AS T1 JOIN routes AS T2 ON T1.apid = T2.src_apid WHERE T1.country = 'China' GROUP BY T1.name ORDER BY count(*) DESC LIMIT 1
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
What is the name of the airport with the most number of routes that start in China?
SELECT T1.name FROM airports AS T1 JOIN routes AS T2 ON T1.apid = T2.src_apid WHERE T1.country = 'China' GROUP BY T1.name ORDER BY count(*) DESC LIMIT 1
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
Find the busiest destination airport that runs most number of routes in China.
SELECT T1.name FROM airports AS T1 JOIN routes AS T2 ON T1.apid = T2.dst_apid WHERE T1.country = 'China' GROUP BY T1.name ORDER BY count(*) DESC LIMIT 1
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
flight_4
What is the name of the airport that is the destination of the most number of routes that start in China?
SELECT T1.name FROM airports AS T1 JOIN routes AS T2 ON T1.apid = T2.dst_apid WHERE T1.country = 'China' GROUP BY T1.name ORDER BY count(*) DESC LIMIT 1
CREATE TABLE routes ( rid integer PRIMARY KEY, dst_apid integer, -- Id of destination airport dst_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the destination airport src_apid bigint, -- Id of source airport src_ap varchar(4), -- 3-letter (IATA) or 4-letter (ICAO) code of the source airport alid bigint, -- Id of airline airline varchar(4), -- 2-letter (IATA) or 3-letter (ICAO) code of the airline codeshare text, -- "Y" if this flight is a codeshare (that is, not operated by -- Airline, but another carrier), empty otherwise FOREIGN KEY(dst_apid) REFERENCES airports(apid), FOREIGN KEY(src_apid) REFERENCES airports(apid), FOREIGN KEY(alid) REFERENCES airlines(alid) ) 3 rows from routes table: rid dst_apid dst_ap src_apid src_ap alid airline codeshare 37 2990 KZ 2965 AER 410 2B None 38 2990 KZ 2966 ASF 410 2B None 39 2962 MRV 2966 ASF 410 2B None CREATE TABLE airports ( apid integer PRIMARY KEY, -- Id of the airport name text NOT NULL, -- Name of airport city text, -- Main city served by airport country text, -- Country or territory where airport is located x real, -- Latitude of airport: Decimal degrees, usually to six -- significant digits. Negative is South, positive is North y real, -- Longitude of airport: Decimal degrees, usually to six -- significant digits. Negative is West, positive is East elevation bigint, -- Altitude of airport measured in feets iata character varchar(3), -- 3-letter IATA code. empty or null if not assigned/unknown icao character varchar(4) -- 4-letter ICAO code. empty or null if not assigned ) 3 rows from airports table: apid name city country x y elevation iata icao 1 Goroka Airport Goroka Papua New Guinea 145.391998 -6.08169 5282 GKA AYGA 2 Madang Airport Madang Papua New Guinea 145.789001 -5.20708 20 MAG AYMD 3 Mount Hagen Kagamuga Airport Mount Hagen Papua New Guinea 144.296005 -5.82679 5388 HGU AYMH CREATE TABLE airlines ( alid integer PRIMARY KEY, -- Id of the airline name text, -- Name of the airline iata varchar(2), -- 2-letter IATA code. empty or null if not assigned/unknown icao varchar(3), -- 3-letter ICAO code. empty or null if not assigned callsign text, -- Airline callsign country text, -- Country or territory where airline is incorporated active varchar(2) -- "Y" if the airline is or has until recently been operational, ) 3 rows from airlines table: alid name iata icao callsign country active -1 Unknown - N/A None None Y 1 Private flight - N/A Y 2 135 Airways GNL GENERAL United States N
tracking_orders
What is the id of the most recent order?
SELECT order_id FROM orders ORDER BY date_order_placed DESC LIMIT 1
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id customer_name customer_details 1 Savannah rerum 2 George est 3 Alberto deleniti CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ) 3 rows from Invoices table: invoice_number invoice_date invoice_details 1 1989-09-03 16:03:05 vitae 2 1989-12-11 16:40:57 magnam 3 1995-10-07 14:13:05 et CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Orders table: order_id customer_id order_status date_order_placed order_details 1 2 Shipped 2009-02-21 15:26:19 None 2 11 Shipped 1974-06-24 22:10:26 None 3 4 Shipped 1982-12-29 21:10:11 None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_name product_details 1 food None 2 book None 3 food None CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ) 3 rows from Order_Items table: order_item_id product_id order_id order_item_status order_item_details 1 4 6 Finish None 2 15 6 Finish None 3 12 15 Finish None CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ) 3 rows from Shipments table: shipment_id order_id invoice_number shipment_tracking_number shipment_date other_shipment_details 1 5 13 3452 1983-08-13 22:34:11 None 2 7 2 0114 1977-11-10 12:11:25 None 3 10 5 478 2006-01-17 03:08:05 None CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ) 3 rows from Shipment_Items table: shipment_id order_item_id 11 12 10 15 10 12
tracking_orders
Find the id of the order made most recently.
SELECT order_id FROM orders ORDER BY date_order_placed DESC LIMIT 1
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id customer_name customer_details 1 Savannah rerum 2 George est 3 Alberto deleniti CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ) 3 rows from Invoices table: invoice_number invoice_date invoice_details 1 1989-09-03 16:03:05 vitae 2 1989-12-11 16:40:57 magnam 3 1995-10-07 14:13:05 et CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Orders table: order_id customer_id order_status date_order_placed order_details 1 2 Shipped 2009-02-21 15:26:19 None 2 11 Shipped 1974-06-24 22:10:26 None 3 4 Shipped 1982-12-29 21:10:11 None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_name product_details 1 food None 2 book None 3 food None CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ) 3 rows from Order_Items table: order_item_id product_id order_id order_item_status order_item_details 1 4 6 Finish None 2 15 6 Finish None 3 12 15 Finish None CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ) 3 rows from Shipments table: shipment_id order_id invoice_number shipment_tracking_number shipment_date other_shipment_details 1 5 13 3452 1983-08-13 22:34:11 None 2 7 2 0114 1977-11-10 12:11:25 None 3 10 5 478 2006-01-17 03:08:05 None CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ) 3 rows from Shipment_Items table: shipment_id order_item_id 11 12 10 15 10 12
tracking_orders
what are the order id and customer id of the oldest order?
SELECT order_id , customer_id FROM orders ORDER BY date_order_placed LIMIT 1
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id customer_name customer_details 1 Savannah rerum 2 George est 3 Alberto deleniti CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ) 3 rows from Invoices table: invoice_number invoice_date invoice_details 1 1989-09-03 16:03:05 vitae 2 1989-12-11 16:40:57 magnam 3 1995-10-07 14:13:05 et CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Orders table: order_id customer_id order_status date_order_placed order_details 1 2 Shipped 2009-02-21 15:26:19 None 2 11 Shipped 1974-06-24 22:10:26 None 3 4 Shipped 1982-12-29 21:10:11 None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_name product_details 1 food None 2 book None 3 food None CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ) 3 rows from Order_Items table: order_item_id product_id order_id order_item_status order_item_details 1 4 6 Finish None 2 15 6 Finish None 3 12 15 Finish None CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ) 3 rows from Shipments table: shipment_id order_id invoice_number shipment_tracking_number shipment_date other_shipment_details 1 5 13 3452 1983-08-13 22:34:11 None 2 7 2 0114 1977-11-10 12:11:25 None 3 10 5 478 2006-01-17 03:08:05 None CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ) 3 rows from Shipment_Items table: shipment_id order_item_id 11 12 10 15 10 12
tracking_orders
Find the order id and customer id associated with the oldest order.
SELECT order_id , customer_id FROM orders ORDER BY date_order_placed LIMIT 1
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id customer_name customer_details 1 Savannah rerum 2 George est 3 Alberto deleniti CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ) 3 rows from Invoices table: invoice_number invoice_date invoice_details 1 1989-09-03 16:03:05 vitae 2 1989-12-11 16:40:57 magnam 3 1995-10-07 14:13:05 et CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Orders table: order_id customer_id order_status date_order_placed order_details 1 2 Shipped 2009-02-21 15:26:19 None 2 11 Shipped 1974-06-24 22:10:26 None 3 4 Shipped 1982-12-29 21:10:11 None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_name product_details 1 food None 2 book None 3 food None CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ) 3 rows from Order_Items table: order_item_id product_id order_id order_item_status order_item_details 1 4 6 Finish None 2 15 6 Finish None 3 12 15 Finish None CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ) 3 rows from Shipments table: shipment_id order_id invoice_number shipment_tracking_number shipment_date other_shipment_details 1 5 13 3452 1983-08-13 22:34:11 None 2 7 2 0114 1977-11-10 12:11:25 None 3 10 5 478 2006-01-17 03:08:05 None CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ) 3 rows from Shipment_Items table: shipment_id order_item_id 11 12 10 15 10 12
tracking_orders
Find the id of the order whose shipment tracking number is "3452".
SELECT order_id FROM shipments WHERE shipment_tracking_number = "3452"
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id customer_name customer_details 1 Savannah rerum 2 George est 3 Alberto deleniti CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ) 3 rows from Invoices table: invoice_number invoice_date invoice_details 1 1989-09-03 16:03:05 vitae 2 1989-12-11 16:40:57 magnam 3 1995-10-07 14:13:05 et CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Orders table: order_id customer_id order_status date_order_placed order_details 1 2 Shipped 2009-02-21 15:26:19 None 2 11 Shipped 1974-06-24 22:10:26 None 3 4 Shipped 1982-12-29 21:10:11 None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_name product_details 1 food None 2 book None 3 food None CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ) 3 rows from Order_Items table: order_item_id product_id order_id order_item_status order_item_details 1 4 6 Finish None 2 15 6 Finish None 3 12 15 Finish None CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ) 3 rows from Shipments table: shipment_id order_id invoice_number shipment_tracking_number shipment_date other_shipment_details 1 5 13 3452 1983-08-13 22:34:11 None 2 7 2 0114 1977-11-10 12:11:25 None 3 10 5 478 2006-01-17 03:08:05 None CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ) 3 rows from Shipment_Items table: shipment_id order_item_id 11 12 10 15 10 12
tracking_orders
Which order's shipment tracking number is "3452"? Give me the id of the order.
SELECT order_id FROM shipments WHERE shipment_tracking_number = "3452"
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id customer_name customer_details 1 Savannah rerum 2 George est 3 Alberto deleniti CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ) 3 rows from Invoices table: invoice_number invoice_date invoice_details 1 1989-09-03 16:03:05 vitae 2 1989-12-11 16:40:57 magnam 3 1995-10-07 14:13:05 et CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Orders table: order_id customer_id order_status date_order_placed order_details 1 2 Shipped 2009-02-21 15:26:19 None 2 11 Shipped 1974-06-24 22:10:26 None 3 4 Shipped 1982-12-29 21:10:11 None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_name product_details 1 food None 2 book None 3 food None CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ) 3 rows from Order_Items table: order_item_id product_id order_id order_item_status order_item_details 1 4 6 Finish None 2 15 6 Finish None 3 12 15 Finish None CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ) 3 rows from Shipments table: shipment_id order_id invoice_number shipment_tracking_number shipment_date other_shipment_details 1 5 13 3452 1983-08-13 22:34:11 None 2 7 2 0114 1977-11-10 12:11:25 None 3 10 5 478 2006-01-17 03:08:05 None CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ) 3 rows from Shipment_Items table: shipment_id order_item_id 11 12 10 15 10 12
tracking_orders
Find the ids of all the order items whose product id is 11.
SELECT order_item_id FROM order_items WHERE product_id = 11
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id customer_name customer_details 1 Savannah rerum 2 George est 3 Alberto deleniti CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ) 3 rows from Invoices table: invoice_number invoice_date invoice_details 1 1989-09-03 16:03:05 vitae 2 1989-12-11 16:40:57 magnam 3 1995-10-07 14:13:05 et CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Orders table: order_id customer_id order_status date_order_placed order_details 1 2 Shipped 2009-02-21 15:26:19 None 2 11 Shipped 1974-06-24 22:10:26 None 3 4 Shipped 1982-12-29 21:10:11 None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_name product_details 1 food None 2 book None 3 food None CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ) 3 rows from Order_Items table: order_item_id product_id order_id order_item_status order_item_details 1 4 6 Finish None 2 15 6 Finish None 3 12 15 Finish None CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ) 3 rows from Shipments table: shipment_id order_id invoice_number shipment_tracking_number shipment_date other_shipment_details 1 5 13 3452 1983-08-13 22:34:11 None 2 7 2 0114 1977-11-10 12:11:25 None 3 10 5 478 2006-01-17 03:08:05 None CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ) 3 rows from Shipment_Items table: shipment_id order_item_id 11 12 10 15 10 12
tracking_orders
Find all the order items whose product id is 11. What are the order item ids?
SELECT order_item_id FROM order_items WHERE product_id = 11
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id customer_name customer_details 1 Savannah rerum 2 George est 3 Alberto deleniti CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ) 3 rows from Invoices table: invoice_number invoice_date invoice_details 1 1989-09-03 16:03:05 vitae 2 1989-12-11 16:40:57 magnam 3 1995-10-07 14:13:05 et CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Orders table: order_id customer_id order_status date_order_placed order_details 1 2 Shipped 2009-02-21 15:26:19 None 2 11 Shipped 1974-06-24 22:10:26 None 3 4 Shipped 1982-12-29 21:10:11 None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_name product_details 1 food None 2 book None 3 food None CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ) 3 rows from Order_Items table: order_item_id product_id order_id order_item_status order_item_details 1 4 6 Finish None 2 15 6 Finish None 3 12 15 Finish None CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ) 3 rows from Shipments table: shipment_id order_id invoice_number shipment_tracking_number shipment_date other_shipment_details 1 5 13 3452 1983-08-13 22:34:11 None 2 7 2 0114 1977-11-10 12:11:25 None 3 10 5 478 2006-01-17 03:08:05 None CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ) 3 rows from Shipment_Items table: shipment_id order_item_id 11 12 10 15 10 12
tracking_orders
List the name of all the distinct customers who have orders with status "Packing".
SELECT DISTINCT T1.customer_name FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status = "Packing"
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id customer_name customer_details 1 Savannah rerum 2 George est 3 Alberto deleniti CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ) 3 rows from Invoices table: invoice_number invoice_date invoice_details 1 1989-09-03 16:03:05 vitae 2 1989-12-11 16:40:57 magnam 3 1995-10-07 14:13:05 et CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Orders table: order_id customer_id order_status date_order_placed order_details 1 2 Shipped 2009-02-21 15:26:19 None 2 11 Shipped 1974-06-24 22:10:26 None 3 4 Shipped 1982-12-29 21:10:11 None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_name product_details 1 food None 2 book None 3 food None CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ) 3 rows from Order_Items table: order_item_id product_id order_id order_item_status order_item_details 1 4 6 Finish None 2 15 6 Finish None 3 12 15 Finish None CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ) 3 rows from Shipments table: shipment_id order_id invoice_number shipment_tracking_number shipment_date other_shipment_details 1 5 13 3452 1983-08-13 22:34:11 None 2 7 2 0114 1977-11-10 12:11:25 None 3 10 5 478 2006-01-17 03:08:05 None CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ) 3 rows from Shipment_Items table: shipment_id order_item_id 11 12 10 15 10 12
tracking_orders
Which customers have orders with status "Packing"? Give me the customer names.
SELECT DISTINCT T1.customer_name FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status = "Packing"
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id customer_name customer_details 1 Savannah rerum 2 George est 3 Alberto deleniti CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ) 3 rows from Invoices table: invoice_number invoice_date invoice_details 1 1989-09-03 16:03:05 vitae 2 1989-12-11 16:40:57 magnam 3 1995-10-07 14:13:05 et CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Orders table: order_id customer_id order_status date_order_placed order_details 1 2 Shipped 2009-02-21 15:26:19 None 2 11 Shipped 1974-06-24 22:10:26 None 3 4 Shipped 1982-12-29 21:10:11 None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_name product_details 1 food None 2 book None 3 food None CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ) 3 rows from Order_Items table: order_item_id product_id order_id order_item_status order_item_details 1 4 6 Finish None 2 15 6 Finish None 3 12 15 Finish None CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ) 3 rows from Shipments table: shipment_id order_id invoice_number shipment_tracking_number shipment_date other_shipment_details 1 5 13 3452 1983-08-13 22:34:11 None 2 7 2 0114 1977-11-10 12:11:25 None 3 10 5 478 2006-01-17 03:08:05 None CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ) 3 rows from Shipment_Items table: shipment_id order_item_id 11 12 10 15 10 12
tracking_orders
Find the details of all the distinct customers who have orders with status "On Road".
SELECT DISTINCT T1.customer_details FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status = "On Road"
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id customer_name customer_details 1 Savannah rerum 2 George est 3 Alberto deleniti CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ) 3 rows from Invoices table: invoice_number invoice_date invoice_details 1 1989-09-03 16:03:05 vitae 2 1989-12-11 16:40:57 magnam 3 1995-10-07 14:13:05 et CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Orders table: order_id customer_id order_status date_order_placed order_details 1 2 Shipped 2009-02-21 15:26:19 None 2 11 Shipped 1974-06-24 22:10:26 None 3 4 Shipped 1982-12-29 21:10:11 None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_name product_details 1 food None 2 book None 3 food None CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ) 3 rows from Order_Items table: order_item_id product_id order_id order_item_status order_item_details 1 4 6 Finish None 2 15 6 Finish None 3 12 15 Finish None CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ) 3 rows from Shipments table: shipment_id order_id invoice_number shipment_tracking_number shipment_date other_shipment_details 1 5 13 3452 1983-08-13 22:34:11 None 2 7 2 0114 1977-11-10 12:11:25 None 3 10 5 478 2006-01-17 03:08:05 None CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ) 3 rows from Shipment_Items table: shipment_id order_item_id 11 12 10 15 10 12
tracking_orders
What are the distinct customers who have orders with status "On Road"? Give me the customer details?
SELECT DISTINCT T1.customer_details FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status = "On Road"
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id customer_name customer_details 1 Savannah rerum 2 George est 3 Alberto deleniti CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ) 3 rows from Invoices table: invoice_number invoice_date invoice_details 1 1989-09-03 16:03:05 vitae 2 1989-12-11 16:40:57 magnam 3 1995-10-07 14:13:05 et CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Orders table: order_id customer_id order_status date_order_placed order_details 1 2 Shipped 2009-02-21 15:26:19 None 2 11 Shipped 1974-06-24 22:10:26 None 3 4 Shipped 1982-12-29 21:10:11 None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_name product_details 1 food None 2 book None 3 food None CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ) 3 rows from Order_Items table: order_item_id product_id order_id order_item_status order_item_details 1 4 6 Finish None 2 15 6 Finish None 3 12 15 Finish None CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ) 3 rows from Shipments table: shipment_id order_id invoice_number shipment_tracking_number shipment_date other_shipment_details 1 5 13 3452 1983-08-13 22:34:11 None 2 7 2 0114 1977-11-10 12:11:25 None 3 10 5 478 2006-01-17 03:08:05 None CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ) 3 rows from Shipment_Items table: shipment_id order_item_id 11 12 10 15 10 12
tracking_orders
What is the name of the customer who has the most orders?
SELECT T1.customer_name FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id ORDER BY count(*) DESC LIMIT 1
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id customer_name customer_details 1 Savannah rerum 2 George est 3 Alberto deleniti CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ) 3 rows from Invoices table: invoice_number invoice_date invoice_details 1 1989-09-03 16:03:05 vitae 2 1989-12-11 16:40:57 magnam 3 1995-10-07 14:13:05 et CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Orders table: order_id customer_id order_status date_order_placed order_details 1 2 Shipped 2009-02-21 15:26:19 None 2 11 Shipped 1974-06-24 22:10:26 None 3 4 Shipped 1982-12-29 21:10:11 None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_name product_details 1 food None 2 book None 3 food None CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ) 3 rows from Order_Items table: order_item_id product_id order_id order_item_status order_item_details 1 4 6 Finish None 2 15 6 Finish None 3 12 15 Finish None CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ) 3 rows from Shipments table: shipment_id order_id invoice_number shipment_tracking_number shipment_date other_shipment_details 1 5 13 3452 1983-08-13 22:34:11 None 2 7 2 0114 1977-11-10 12:11:25 None 3 10 5 478 2006-01-17 03:08:05 None CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ) 3 rows from Shipment_Items table: shipment_id order_item_id 11 12 10 15 10 12
tracking_orders
Which customer made the most orders? Find the customer name.
SELECT T1.customer_name FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id ORDER BY count(*) DESC LIMIT 1
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id customer_name customer_details 1 Savannah rerum 2 George est 3 Alberto deleniti CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ) 3 rows from Invoices table: invoice_number invoice_date invoice_details 1 1989-09-03 16:03:05 vitae 2 1989-12-11 16:40:57 magnam 3 1995-10-07 14:13:05 et CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Orders table: order_id customer_id order_status date_order_placed order_details 1 2 Shipped 2009-02-21 15:26:19 None 2 11 Shipped 1974-06-24 22:10:26 None 3 4 Shipped 1982-12-29 21:10:11 None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_name product_details 1 food None 2 book None 3 food None CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ) 3 rows from Order_Items table: order_item_id product_id order_id order_item_status order_item_details 1 4 6 Finish None 2 15 6 Finish None 3 12 15 Finish None CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ) 3 rows from Shipments table: shipment_id order_id invoice_number shipment_tracking_number shipment_date other_shipment_details 1 5 13 3452 1983-08-13 22:34:11 None 2 7 2 0114 1977-11-10 12:11:25 None 3 10 5 478 2006-01-17 03:08:05 None CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ) 3 rows from Shipment_Items table: shipment_id order_item_id 11 12 10 15 10 12
tracking_orders
What is the customer id of the customer who has the most orders?
SELECT T1.customer_id FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id ORDER BY count(*) DESC LIMIT 1
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id customer_name customer_details 1 Savannah rerum 2 George est 3 Alberto deleniti CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ) 3 rows from Invoices table: invoice_number invoice_date invoice_details 1 1989-09-03 16:03:05 vitae 2 1989-12-11 16:40:57 magnam 3 1995-10-07 14:13:05 et CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Orders table: order_id customer_id order_status date_order_placed order_details 1 2 Shipped 2009-02-21 15:26:19 None 2 11 Shipped 1974-06-24 22:10:26 None 3 4 Shipped 1982-12-29 21:10:11 None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_name product_details 1 food None 2 book None 3 food None CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ) 3 rows from Order_Items table: order_item_id product_id order_id order_item_status order_item_details 1 4 6 Finish None 2 15 6 Finish None 3 12 15 Finish None CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ) 3 rows from Shipments table: shipment_id order_id invoice_number shipment_tracking_number shipment_date other_shipment_details 1 5 13 3452 1983-08-13 22:34:11 None 2 7 2 0114 1977-11-10 12:11:25 None 3 10 5 478 2006-01-17 03:08:05 None CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ) 3 rows from Shipment_Items table: shipment_id order_item_id 11 12 10 15 10 12