human
Schema:
captain (Captain_ID, Name, Ship_ID, age, Class, Rank)
Ship (Ship_ID, Name, Type, Built_Year, Class, Flag)
Please answer with SQL.
assistant
Sure, I understand.
human
List all ship names in the order of built year and class.
assistant
SELECT name FROM ship ORDER BY built_year , CLASS
human
Group by ships by flag, and return number of ships that have each flag.
assistant
SELECT count(*) , flag FROM ship GROUP BY flag
human
In which year were most of ships built?
assistant
SELECT built_year FROM ship GROUP BY built_year ORDER BY count(*) DESC LIMIT 1
human
Find the name of the ships that have more than one captain.
assistant
SELECT t1.name FROM ship AS t1 JOIN captain AS t2 ON t1.ship_id = t2.ship_id GROUP BY t2.ship_id HAVING count(*) > 1
human
what are the names and classes of the ships that do not have any captain yet?
assistant
SELECT name , CLASS FROM ship WHERE ship_id NOT IN (SELECT ship_id FROM captain)
human
how many ships are there?
assistant
SELECT COUNT( * ) FROM ship ;