Database: flight_4

Question: How many airports are there per city in the United States? Order the cities by decreasing number of airports.
SQL: SELECT count(*) ,  city FROM airports WHERE country  =  'United States' GROUP BY city ORDER BY count(*) DESC

Question: Return the cities with more than 3 airports in the United States.
SQL: SELECT city FROM airports WHERE country  =  'United States' GROUP BY city HAVING count(*)  >  3

Question: How many cities are there that have more than 3 airports?
SQL: SELECT count(*) FROM (SELECT city FROM airports GROUP BY city HAVING count(*)  >  3)

Question: List the cities which have more than one airport and number of airports.
SQL: SELECT city ,  count(*) FROM airports GROUP BY city HAVING count(*)  >  1

Question: List the cities which have more than 2 airports sorted by the number of airports.
SQL: SELECT city FROM airports GROUP BY city HAVING count(*)  >  2 ORDER BY count(*)

Question: Find the number of routes for each source airport and the airport name.
SQL: SELECT count(*),  T1.name FROM airports AS T1 JOIN routes AS T2 ON T1.apid  =  T2.src_apid GROUP BY T1.name

Question: Find the number of routes and airport name for each source airport, order the results by decreasing number of routes.
SQL: 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

Question: Find the cities which have exactly two airports.
SQL: SELECT city FROM airports GROUP BY city HAVING count(*)  =  2

Question: For each country and airline name, how many routes are there?
SQL: 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

Question: Find the number of routes with destination airports in Italy.
SQL: SELECT count(*) FROM routes AS T1 JOIN airports AS T2 ON T1.dst_apid  =  T2.apid WHERE T2.country  =  'Italy'

Question: Return the number of routes with destination airport in Italy operated by the airline with name 'American Airlines'.
SQL: 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'

Question: Find the number of routes that list John F Kennedy International Airport as a destination.
SQL: SELECT count(*) FROM airports AS T1 JOIN routes AS T2 ON T1.apid  =  T2.dst_apid WHERE T1.name  =  'John F Kennedy International Airport'

Question: Find the number of routes from the United States to Canada.
SQL: 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')

Question: Find the id of routes whose source and destination airports are in the United States.
SQL: 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')