Database: swimming

Question: What is the name of the event that happened in the most recent year?
SQL: SELECT name FROM event ORDER BY YEAR DESC LIMIT 1

Question: Find the name of the stadium that has the maximum capacity.
SQL: SELECT name FROM stadium ORDER BY capacity DESC LIMIT 1

Question: Find the names of stadiums whose capacity is smaller than the average capacity.
SQL: SELECT name FROM stadium WHERE capacity  <  (SELECT avg(capacity) FROM stadium)

Question: Find the country that has the most stadiums.
SQL: SELECT country FROM stadium GROUP BY country ORDER BY count(*) DESC LIMIT 1

Question: Which country has at most 3 stadiums listed?
SQL: SELECT country FROM stadium GROUP BY country HAVING count(*)  <=  3

Question: Which country has both stadiums with capacity greater than 60000 and stadiums with capacity less than 50000?
SQL: SELECT country FROM stadium WHERE capacity  >  60000 INTERSECT SELECT country FROM stadium WHERE capacity  <  50000

Question: Which countries do not have a stadium that was opened after 2006?
SQL: SELECT country FROM stadium EXCEPT SELECT country FROM stadium WHERE opening_year  >  2006

Question: List countries that have more than one swimmer.
SQL: SELECT nationality ,  count(*) FROM swimmer GROUP BY nationality HAVING count(*)  >  1

Question: Find the names of swimmers who has a result of "win".
SQL: SELECT t1.name FROM swimmer AS t1 JOIN record AS t2 ON t1.id  =  t2.swimmer_id WHERE RESULT  =  'Win'

Question: What is the name of the stadium which held the most events?
SQL: SELECT t1.name FROM stadium AS t1 JOIN event AS t2 ON t1.id  =  t2.stadium_id GROUP BY t2.stadium_id ORDER BY count(*) DESC LIMIT 1

Question: Find the name and capacity of the stadium where the event named "World Junior" happened.
SQL: SELECT t1.name ,  t1.capacity FROM stadium AS t1 JOIN event AS t2 ON t1.id  =  t2.stadium_id WHERE t2.name  =  'World Junior'

Question: Find the names of stadiums which have never had any event.
SQL: SELECT name FROM stadium WHERE id NOT IN (SELECT stadium_id FROM event)

Question: Find the name of the swimmer who has the most records.
SQL: SELECT t1.name FROM swimmer AS t1 JOIN record AS t2 ON t1.id  =  t2.swimmer_id GROUP BY t2.swimmer_id ORDER BY count(*) DESC LIMIT 1

Question: Find the name of the swimmer who has at least 2 records.
SQL: SELECT t1.name FROM swimmer AS t1 JOIN record AS t2 ON t1.id  =  t2.swimmer_id GROUP BY t2.swimmer_id HAVING count(*)  >=  2

Question: Find the name and nationality of the swimmer who has won (i.e., has a result of "win") more than 1 time.
SQL: SELECT t1.name ,  t1.nationality FROM swimmer AS t1 JOIN record AS t2 ON t1.id  =  t2.swimmer_id WHERE RESULT  =  'Win' GROUP BY t2.swimmer_id HAVING count(*)  >  1

Question: Find the names of the swimmers who have no record.
SQL: SELECT name FROM swimmer WHERE id NOT IN (SELECT swimmer_id FROM record)

Question: Find the names of the swimmers who have both "win" and "loss" results in the record.
SQL: SELECT t1.name FROM swimmer AS t1 JOIN record AS t2 ON t1.id  =  t2.swimmer_id WHERE RESULT  =  'Win' INTERSECT SELECT t1.name FROM swimmer AS t1 JOIN record AS t2 ON t1.id  =  t2.swimmer_id WHERE RESULT  =  'Loss'