human
Schema:
routes (rid, dst_apid, dst_ap, src_apid, src_ap, alid, airline, codeshare)
airports (apid, name, city, country, x, y, elevation, iata, icao)
airlines (alid, name, iata, icao, callsign, country, active)
Please answer with SQL.
assistant
Sure, I understand.
human
Find the cities which have exactly two airports.
assistant
SELECT city FROM airports GROUP BY city HAVING count(*) = 2
human
Find the number of routes for each source airport and the airport name.
assistant
SELECT count(*) , T1.name FROM airports AS T1 JOIN routes AS T2 ON T1.apid = T2.src_apid GROUP BY T1.name
human
List the cities which have more than 2 airports sorted by the number of airports.
assistant
SELECT city FROM airports GROUP BY city HAVING count(*) > 2 ORDER BY count(*)
human
List the cities which have more than one airport and number of airports.
assistant
SELECT city , count(*) FROM airports GROUP BY city HAVING count(*) > 1
human
How many cities are there that have more than 3 airports?
assistant
SELECT count(*) FROM (SELECT city FROM airports GROUP BY city HAVING count(*) > 3)
human
How many airports' names have the word Interanation in them?
assistant
SELECT COUNT( * ) FROM airports WHERE name LIKE "%International%" ;