Database: formula_1

Question: What is the name of the race held most recently?
SQL: SELECT name FROM races ORDER BY date DESC LIMIT 1

Question: What is the name and date of the most recent race?
SQL: SELECT name ,  date FROM races ORDER BY date DESC LIMIT 1

Question: Find the names of all races held in 2017.
SQL: SELECT name FROM races WHERE YEAR = 2017

Question: Find the distinct names of all races held between 2014 and 2017?
SQL: SELECT DISTINCT name FROM races WHERE YEAR BETWEEN 2014 AND 2017

Question: List the forename and surname of all distinct drivers who once had laptime less than 93000 milliseconds?
SQL: SELECT DISTINCT T1.forename ,  T1.surname FROM drivers AS T1 JOIN laptimes AS T2 ON T1.driverid = T2.driverid WHERE T2.milliseconds < 93000

Question: Find all the distinct id and nationality of drivers who have had laptime more than 100000 milliseconds?
SQL: SELECT DISTINCT T1.driverid ,  T1.nationality FROM drivers AS T1 JOIN laptimes AS T2 ON T1.driverid = T2.driverid WHERE T2.milliseconds >  100000

Question: What are the forename and surname of the driver who has the smallest laptime?
SQL: SELECT T1.forename ,  T1.surname FROM drivers AS T1 JOIN laptimes AS T2 ON T1.driverid = T2.driverid ORDER BY T2.milliseconds LIMIT 1

Question: What is the id and family name of the driver who has the longest laptime?
SQL: SELECT T1.driverid ,  T1.surname FROM drivers AS T1 JOIN laptimes AS T2 ON T1.driverid = T2.driverid ORDER BY T2.milliseconds DESC LIMIT 1

Question: What is the id, forename and surname of the driver who had the first position in terms of laptime at least twice?
SQL: SELECT T1.driverid ,  T1.forename ,  T1.surname FROM drivers AS T1 JOIN laptimes AS T2 ON T1.driverid = T2.driverid WHERE POSITION  =  '1' GROUP BY T1.driverid HAVING count(*)  >=  2

Question: How many drivers participated in the race Australian Grand Prix held in 2009?
SQL: SELECT count(*) FROM results AS T1 JOIN races AS T2 ON T1.raceid = T2.raceid WHERE T2.name = "Australian Grand Prix" AND YEAR = 2009

Question: How many drivers did not participate in the races held in 2009?
SQL: SELECT count(DISTINCT driverId) FROM results WHERE raceId NOT IN( SELECT raceId FROM races WHERE YEAR != 2009 )

Question: Give me a list of names and years of races that had any driver whose forename is Lewis?
SQL: SELECT T2.name ,  T2.year FROM results AS T1 JOIN races AS T2 ON T1.raceid = T2.raceid JOIN drivers AS T3 ON T1.driverid = T3.driverid WHERE T3.forename = "Lewis"

Question: Find the forename and surname of drivers whose nationality is German?
SQL: SELECT forename ,  surname FROM drivers WHERE nationality = "German"

Question: Find the ids and forenames of drivers who participated both the races with name Australian Grand Prix and the races with name Chinese Grand Prix?
SQL: SELECT T2.driverid ,  T3.forename FROM races AS T1 JOIN results AS T2 ON T1.raceid = T2.raceid JOIN drivers AS T3 ON T2.driverid  =  T3.driverid WHERE T1.name = "Australian Grand Prix" INTERSECT SELECT T2.driverid ,  T3.forename FROM races AS T1 JOIN results AS T2 ON T1.raceid = T2.raceid JOIN drivers AS T3 ON T2.driverid  =  T3.driverid WHERE T1.name = "Chinese Grand Prix"