human
Schema:
airport (id, City, Country, IATA, ICAO, name)
operate_company (id, name, Type, Principal_activities, Incorporated_in, Group_Equity_Shareholding)
flight (id, Vehicle_Flight_number, Date, Pilot, Velocity, Altitude, airport_id, company_id)
Please answer with SQL.
assistant
Sure, I understand.
human
List the names of all the companies.
assistant
SELECT name FROM operate_company;
human
How many flights did each of these companies operate?
assistant
SELECT t1.name , COUNT( * ) FROM operate_company AS t1 JOIN flight AS t2 ON t1.id = t2.company_id GROUP BY t1.id;
human
Show me only the companies that operated more than one flight.
assistant
SELECT t1.name , COUNT( * ) FROM operate_company AS t1 JOIN flight AS t2 ON t1.id = t2.company_id GROUP BY t1.id HAVING COUNT( * ) > 1;
human
Show me only the ids and the names of these companies.
assistant
SELECT T1.id , T1.name FROM operate_company AS T1 JOIN flight AS t2 ON T1.id = T2.company_id GROUP BY T1.id HAVING COUNT( * ) > 1 ;