CREATE TABLE circuits (
    circuitId NUMBER PRIMARY KEY,
    circuitRef TEXT,
    name TEXT,
    location TEXT,
    country TEXT,
    lat NUMBER,
    lng NUMBER,
    alt NUMBER,
    url TEXT
);
CREATE TABLE races (
    raceId NUMBER PRIMARY KEY,
    year NUMBER,
    round NUMBER,
    circuitId NUMBER,
    name TEXT,
    date TEXT,
    time TEXT,
    url TEXT,
    FOREIGN KEY ("circuitId") REFERENCES circuits("circuitId")
);
CREATE TABLE drivers (
    driverId NUMBER PRIMARY KEY,
    driverRef TEXT,
    number NUMBER,
    code TEXT,
    forename TEXT,
    surname TEXT,
    dob TEXT,
    nationality TEXT,
    url TEXT
);
CREATE TABLE status (
    statusId NUMBER PRIMARY KEY,
    status TEXT
);
CREATE TABLE seasons (
    year NUMBER PRIMARY KEY,
    url TEXT
);
CREATE TABLE constructors (
    constructorId NUMBER PRIMARY KEY,
    constructorRef TEXT,
    name TEXT,
    nationality TEXT,
    url TEXT
);
CREATE TABLE constructorStandings (
    constructorStandingsId NUMBER PRIMARY KEY,
    raceId NUMBER,
    constructorId NUMBER,
    points NUMBER,
    position NUMBER,
    positionText TEXT,
    wins NUMBER,
    FOREIGN KEY ("raceId") REFERENCES races("raceId"),
    FOREIGN KEY ("constructorId") REFERENCES constructors("constructorId")
);
CREATE TABLE results (
    resultId NUMBER PRIMARY KEY,
    raceId NUMBER,
    driverId NUMBER,
    constructorId NUMBER,
    number NUMBER,
    grid NUMBER,
    position NUMBER,
    positionText TEXT,
    positionOrder NUMBER,
    points NUMBER,
    laps NUMBER,
    time TEXT,
    milliseconds NUMBER,
    fastestLap NUMBER,
    rank NUMBER,
    fastestLapTime TEXT,
    fastestLapSpeed TEXT,
    statusId NUMBER,
    FOREIGN KEY ("driverId") REFERENCES drivers("driverId"),
    FOREIGN KEY ("raceId") REFERENCES races("raceId"),
    FOREIGN KEY ("constructorId") REFERENCES constructors("constructorId")
);
CREATE TABLE driverStandings (
    driverStandingsId NUMBER PRIMARY KEY,
    raceId NUMBER,
    driverId NUMBER,
    points NUMBER,
    position NUMBER,
    positionText TEXT,
    wins NUMBER,
    FOREIGN KEY ("driverId") REFERENCES drivers("driverId"),
    FOREIGN KEY ("raceId") REFERENCES races("raceId")
);
CREATE TABLE constructorResults (
    constructorResultsId NUMBER PRIMARY KEY,
    raceId NUMBER,
    constructorId NUMBER,
    points NUMBER,
    status NUMBER,
    FOREIGN KEY ("raceId") REFERENCES races("raceId"),
    FOREIGN KEY ("constructorId") REFERENCES constructors("constructorId")
);
CREATE TABLE qualifying (
    qualifyId NUMBER PRIMARY KEY,
    raceId NUMBER,
    driverId NUMBER,
    constructorId NUMBER,
    number NUMBER,
    position NUMBER,
    q1 TEXT,
    q2 TEXT,
    q3 TEXT,
    FOREIGN KEY ("driverId") REFERENCES drivers("driverId"),
    FOREIGN KEY ("raceId") REFERENCES races("raceId"),
    FOREIGN KEY ("constructorId") REFERENCES constructors("constructorId")
);
CREATE TABLE pitStops (
    raceId NUMBER PRIMARY KEY,
    driverId NUMBER,
    stop NUMBER,
    lap NUMBER,
    time TEXT,
    duration TEXT,
    milliseconds NUMBER,
    FOREIGN KEY ("driverId") REFERENCES drivers("driverId"),
    FOREIGN KEY ("raceId") REFERENCES races("raceId")
);
CREATE TABLE lapTimes (
    raceId NUMBER PRIMARY KEY,
    driverId NUMBER,
    lap NUMBER,
    position NUMBER,
    time TEXT,
    milliseconds NUMBER,
    FOREIGN KEY ("driverId") REFERENCES drivers("driverId"),
    FOREIGN KEY ("raceId") REFERENCES races("raceId")
);

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 of the race that occurred 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: What is the name and date of the race that occurred most recently?
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: What are the names of all the races that occurred in the year 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: What are the unique names of all race 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: What are the forenames and surnames of all unique drivers who had a lap time of 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 different driver ids and nationalities of all drivers who had a laptime of 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 forename and surname of the driver with the shortest 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 and last name of the driver with 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, forname 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: What is the id, first name, and last name of the driver who was in the first position for 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 were in the 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: How many drivers did not race in 2009?
SQL: SELECT count(DISTINCT driverId) FROM results WHERE raceId NOT IN( SELECT raceId FROM races WHERE YEAR != 2009 )